forked from ynput/OpenPype
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dec089f
commit cfc1f90
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
openpype/modules/default_modules/shotgrid/plugins/publish/validate_shotgrid_user.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |