Added configurable maximum file size of review upload to Slack

This commit is contained in:
Petr Kalis 2022-03-24 13:47:07 +01:00
parent 0bfb3c3dfc
commit ce4caeabd3
3 changed files with 42 additions and 14 deletions

View file

@ -35,20 +35,25 @@ class CollectSlackFamilies(pyblish.api.InstancePlugin):
return
# make slack publishable
if profile:
self.log.info("Found profile: {}".format(profile))
if instance.data.get('families'):
instance.data['families'].append('slack')
else:
instance.data['families'] = ['slack']
if not profile:
return
instance.data["slack_channel_message_profiles"] = \
profile["channel_messages"]
self.log.info("Found profile: {}".format(profile))
if instance.data.get('families'):
instance.data['families'].append('slack')
else:
instance.data['families'] = ['slack']
slack_token = (instance.context.data["project_settings"]
["slack"]
["token"])
instance.data["slack_token"] = slack_token
selected_profiles = profile["channel_messages"]
for prof in selected_profiles:
prof["review_upload_limit"] = profile.get("review_upload_limit",
50)
instance.data["slack_channel_message_profiles"] = selected_profiles
slack_token = (instance.context.data["project_settings"]
["slack"]
["token"])
instance.data["slack_token"] = slack_token
def main_family_from_instance(self, instance): # TODO yank from integrate
"""Returns main family of entered instance."""

View file

@ -35,7 +35,7 @@ class IntegrateSlackAPI(pyblish.api.InstancePlugin):
message = self._get_filled_message(message_profile["message"],
instance,
review_path)
self.log.info("message:: {}".format(message))
self.log.debug("message:: {}".format(message))
if not message:
return
@ -43,7 +43,8 @@ class IntegrateSlackAPI(pyblish.api.InstancePlugin):
publish_files.add(thumbnail_path)
if message_profile["upload_review"] and review_path:
publish_files.add(review_path)
message, publish_files = self._handle_review_upload(
message, message_profile, publish_files, review_path)
project = instance.context.data["anatomyData"]["project"]["code"]
for channel in message_profile["channels"]:
@ -75,6 +76,19 @@ class IntegrateSlackAPI(pyblish.api.InstancePlugin):
dbcon = mongo_client[database_name]["notification_messages"]
dbcon.insert_one(msg)
def _handle_review_upload(self, message, message_profile, publish_files,
review_path):
"""Check if uploaded file is not too large"""
review_file_size_MB = os.path.getsize(review_path) / 1024 / 1024
file_limit = message_profile.get("review_upload_limit", 50)
if review_file_size_MB > file_limit:
if review_path not in message:
message += "\n Review upload omitted because of " + \
"file size, file located at: {}".format(review_path)
else:
publish_files.add(review_path)
return message, publish_files
def _get_filled_message(self, message_templ, instance, review_path=None):
"""Use message_templ and data from instance to get message content.