From cfc1f902ad94511493e0ba34ce2c3b4c3a4e2831 Mon Sep 17 00:00:00 2001 From: "clement.hector" Date: Mon, 24 Jan 2022 11:29:55 +0100 Subject: [PATCH] Add validate user --- .../plugins/publish/validate_shotgrid_user.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 openpype/modules/default_modules/shotgrid/plugins/publish/validate_shotgrid_user.py diff --git a/openpype/modules/default_modules/shotgrid/plugins/publish/validate_shotgrid_user.py b/openpype/modules/default_modules/shotgrid/plugins/publish/validate_shotgrid_user.py new file mode 100644 index 00000000000..7343c478083 --- /dev/null +++ b/openpype/modules/default_modules/shotgrid/plugins/publish/validate_shotgrid_user.py @@ -0,0 +1,36 @@ +import pyblish.api +import openpype.api + + +class ValidateShotgridUser(pyblish.api.ContextPlugin): + """ + Check if user is valid and have access to the project. + """ + + label = "Validate Shotgrid User" + order = openpype.api.ValidateContentsOrder + + def process(self, context): + sg = context.data.get('shotgridSession') + + login = context.data.get('shotgridUser') + self.log.info("Login shotgrid set in OpenPype is {}".format(login)) + project = context.data.get("shotgridProject") + self.log.info("Current shotgun project is {}".format(project)) + + if not (login and sg and project): + raise KeyError() + + user = sg.find_one( + "HumanUser", + [["login", "is", login]], + ["projects"] + ) + + self.log.info(user) + self.log.info(login) + user_projects_id = [p["id"] for p in user.get("projects", [])] + if not project.get('id') in user_projects_id: + raise PermissionError("Login {} don't have access to the project {}".format(login, project)) + + self.log.info("Login {} have access to the project {}".format(login, project))