Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

[QUAD] Enhancement: Reactivating ftrack user while he has active deadline jobs #6298

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import ftrack_api
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'ftrack_api' imported but unused

from openpype_modules.ftrack.lib import BaseEvent
from openpype.modules import ModulesManager


class KeepUserActiveForDeadline(BaseEvent):

def launch(self, session, event):
"""Ensure the user stays active while having ongoing job(s) in the Deadline."""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (87 > 79 characters)

if not event.get('data'):
return

entities_info = event['data'].get('entities')
if not entities_info:
return

entity_info = entities_info[0]
# check if a user has been deactivated
if entity_info.get('entity_type') != "User":
return
if entity_info.get('action', "") != "update":
return
if "isactive" not in entity_info.get('changes', {}):
return
if entity_info['changes']['isactive'].get('new') != False:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparison to False should be 'if cond is not False:' or 'if cond:'

return

user = session.get('User', entity_info.get('entityId'))
if not user:
return

job_ids = self.get_user_active_deadline_jobs(user['username'])
if not job_ids:
return

# Re-activate the account
user['is_active'] = True
session.commit()
self.log.info("the user {} has been re-activated".format(user['username']))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (83 > 79 characters)


# Return the issue message form
items = [
{
"type": "label",
"value": "#Warning: The user has been re-activated!"
},
{
"type": "label",
"value": "The following jobs from this user are currently active "
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (82 > 79 characters)

"on deadline:\n{}".format("\n".join(job_ids))
},
{
"type": "label",
"value": "Please try later when all the jobs are done."
}
]

self.show_interface(
items,
title="The User Must Remain Active",
event=event,
submit_btn_label="I will try later!"
)
return True

def get_user_active_deadline_jobs(self, user):
"""Get all active deadline jobs of the user
"""
manager = ModulesManager()
deadline_module = manager.modules_by_name["deadline"]
deadline_url = deadline_module.deadline_urls["default"]

if not deadline_module.enabled or not deadline_url:
self.log.info("Deadline not enabled or URL not found, skipping.")
return None

requested_arguments = {
"States": "Active"
}

jobs = deadline_module.get_deadline_data(
deadline_url,
"jobs",
log=None,
**requested_arguments
)

user_jobs = []
for job in jobs:
if job['Props']['Env'].get('FTRACK_API_USER') == user:
user_jobs.append(job['_id'])

return user_jobs


def register(session):
"""Register plugin. Called when used as an plugin."""
KeepUserActiveForDeadline(session).register()
Loading