Skip to content

Commit

Permalink
Add validate user
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementHector committed Feb 7, 2022
1 parent dec089f commit cfc1f90
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit cfc1f90

Please sign in to comment.