mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Creates Checkbox for auto-sync event in Project. Action update roles and group on existing attributes
This commit is contained in:
parent
06d473425d
commit
884ac36f25
1 changed files with 39 additions and 0 deletions
|
|
@ -53,11 +53,19 @@ class AvalonIdAttribute(BaseAction):
|
|||
})
|
||||
session.commit()
|
||||
try:
|
||||
# Checkbox for event sync
|
||||
cbxSyncName = 'avalon_auto_sync'
|
||||
cbxSyncLabel = 'Avalon auto-sync'
|
||||
cbxSyncExist = False
|
||||
|
||||
# Attribute Name and Label
|
||||
custAttrName = 'avalon_mongo_id'
|
||||
custAttrLabel = 'Avalon/Mongo Id'
|
||||
|
||||
attrs_update = set()
|
||||
# Types that don't need object_type_id
|
||||
base = {'show'}
|
||||
|
||||
# Don't create custom attribute on these entity types:
|
||||
exceptions = ['task', 'milestone']
|
||||
exceptions.extend(base)
|
||||
|
|
@ -77,6 +85,7 @@ class AvalonIdAttribute(BaseAction):
|
|||
|
||||
# Get IDs of filtered object types
|
||||
all_obj_types_id = set()
|
||||
|
||||
for obj in all_obj_types:
|
||||
all_obj_types_id.add(obj['id'])
|
||||
|
||||
|
|
@ -84,11 +93,16 @@ class AvalonIdAttribute(BaseAction):
|
|||
current_cust_attr = session.query('CustomAttributeConfiguration').all()
|
||||
# Filter already existing AvalonMongoID attr.
|
||||
for attr in current_cust_attr:
|
||||
if attr['key'] == cbxSyncName:
|
||||
cbxSyncExist = True
|
||||
cbxAttribute = attr
|
||||
if attr['key'] == custAttrName:
|
||||
if attr['entity_type'] in base:
|
||||
base.remove(attr['entity_type'])
|
||||
attrs_update.add(attr)
|
||||
if attr['object_type_id'] in all_obj_types_id:
|
||||
all_obj_types_id.remove(attr['object_type_id'])
|
||||
attrs_update.add(attr)
|
||||
|
||||
# Set session back to begin("session.query" raises error on commit)
|
||||
session.rollback()
|
||||
|
|
@ -116,6 +130,24 @@ class AvalonIdAttribute(BaseAction):
|
|||
else:
|
||||
group = groups[0]
|
||||
|
||||
# Checkbox for auto-sync event / Create or Update(roles + group)
|
||||
if cbxSyncExist is False:
|
||||
cbxType = session.query('CustomAttributeType where name is "boolean"').first()
|
||||
session.create('CustomAttributeConfiguration', {
|
||||
'entity_type': 'show',
|
||||
'type': cbxType,
|
||||
'label': cbxSyncLabel,
|
||||
'key': cbxSyncName,
|
||||
'default': False,
|
||||
'write_security_roles': roles,
|
||||
'read_security_roles': roles,
|
||||
'group':group,
|
||||
})
|
||||
else:
|
||||
cbxAttribute['write_security_roles'] = roles
|
||||
cbxAttribute['read_security_roles'] = roles
|
||||
cbxAttribute['group'] = group
|
||||
|
||||
for entity_type in base:
|
||||
# Create a custom attribute configuration.
|
||||
session.create('CustomAttributeConfiguration', {
|
||||
|
|
@ -145,11 +177,18 @@ class AvalonIdAttribute(BaseAction):
|
|||
'config': json.dumps({'markdown': False})
|
||||
})
|
||||
|
||||
for attr in attrs_update:
|
||||
attr['write_security_roles'] = roles
|
||||
attr['read_security_roles'] = roles
|
||||
attr['group'] = group
|
||||
|
||||
job['status'] = 'done'
|
||||
session.commit()
|
||||
|
||||
except Exception as e:
|
||||
session.rollback()
|
||||
job['status'] = 'failed'
|
||||
session.commit()
|
||||
self.log.error("Creating custom attributes failed ({})".format(e))
|
||||
|
||||
return True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue