diff --git a/lingvodoc/schema/gql_entity.py b/lingvodoc/schema/gql_entity.py index e547f87ec..e346b64a3 100644 --- a/lingvodoc/schema/gql_entity.py +++ b/lingvodoc/schema/gql_entity.py @@ -248,27 +248,38 @@ def mutate(root, info, **args): additional_metadata=additional_metadata, parent=parent) - # Acception override check. - # Currently disabled. + # Acception permission check. + # Admin is assumed to have all permissions. - #group = DBSession.query(dbGroup).join(dbBaseGroup).filter(dbBaseGroup.subject == 'lexical_entries_and_entities', - # dbGroup.subject_client_id == dbentity.parent.parent.client_id, - # dbGroup.subject_object_id == dbentity.parent.parent.object_id, - # dbBaseGroup.action == 'create').one() + create_flag = (user.id == 1) - #override_group = DBSession.query(dbGroup).join(dbBaseGroup).filter( - # dbBaseGroup.subject == 'lexical_entries_and_entities', - # dbGroup.subject_override == True, - # dbBaseGroup.action == 'create').one() + if not create_flag: - #if user in group.users or user in override_group.users: - # dbentity.publishingentity.accepted = True + group = DBSession.query(dbGroup).join(dbBaseGroup).filter( + dbBaseGroup.subject == 'lexical_entries_and_entities', + dbGroup.subject_client_id == parent.parent_client_id, + dbGroup.subject_object_id == parent.parent_object_id, + dbBaseGroup.action == 'create').one() + + create_flag = ( + user.is_active and user in group.users) + + if not create_flag: + + override_group = DBSession.query(dbGroup).join(dbBaseGroup).filter( + dbBaseGroup.subject == 'lexical_entries_and_entities', + dbGroup.subject_override == True, + dbBaseGroup.action == 'create').one() + + create_flag = ( + user.is_active and user in override_group.users) + + if create_flag: + dbentity.publishingentity.accepted = True if upper_level: dbentity.upper_level = upper_level - dbentity.publishingentity.accepted = True - # If the entity is being created by the admin, we automatically publish it. if user.id == 1: diff --git a/lingvodoc/schema/gql_lexicalentry.py b/lingvodoc/schema/gql_lexicalentry.py index 10007b522..099495b57 100644 --- a/lingvodoc/schema/gql_lexicalentry.py +++ b/lingvodoc/schema/gql_lexicalentry.py @@ -42,6 +42,11 @@ import time import string import random +import logging + + +# Setting up logging. +log = logging.getLogger(__name__) class LexicalEntry(LingvodocObjectType): @@ -361,8 +366,54 @@ def mutate(root, info, **args): if parent not in lexical_entries: lexical_entries.append(parent) + # Override create permission check, depends only on the user. + # Admin is assumed to have all permissions. + + create_override_flag = (user.id == 1) + + if not create_override_flag: + + group = DBSession.query(dbGroup).join(dbBaseGroup).filter( + dbBaseGroup.subject == 'lexical_entries_and_entities', + dbGroup.subject_override == True, + dbBaseGroup.action == 'create').one() + + create_override_flag = ( + user.is_active and user in group.users) + + create_flag_dict = {} + for lex in lexical_entries: + + create_flag = create_override_flag + + # Create permission check, depends on the perspective of the lexical entry. + + if not create_flag: + + perspective_id = ( + lex.parent_client_id, lex.parent_object_id) + + if perspective_id in create_flag_dict: + create_flag = create_flag_dict[perspective_id] + + else: + + group = DBSession.query(dbGroup).join(dbBaseGroup).filter( + dbBaseGroup.subject == 'lexical_entries_and_entities', + dbGroup.subject_client_id == perspective_id[0], + dbGroup.subject_object_id == perspective_id[1], + dbBaseGroup.action == 'create').one() + + create_flag = ( + user.is_active and user in group.users) + + create_flag_dict[perspective_id] = create_flag + + # Ensuring that the lexical entry has all link tags. + for tag in tags: + tag_entity = DBSession.query(dbEntity) \ .join(dbEntity.field) \ .join(dbEntity.publishingentity) \ @@ -371,21 +422,16 @@ def mutate(root, info, **args): dbField.object_id == field_id[1], dbEntity.content == tag, dbEntity.marked_for_deletion == False).first() + if not tag_entity: - tag_entity = dbEntity(client_id=client.id, - field=field, content=tag, parent=lex) - group = DBSession.query(dbGroup).join(dbBaseGroup).filter( - dbBaseGroup.subject == 'lexical_entries_and_entities', - dbGroup.subject_client_id == tag_entity.parent.parent.client_id, - dbGroup.subject_object_id == tag_entity.parent.parent.object_id, - dbBaseGroup.action == 'create').one() - if user.is_active and user in group.users: - tag_entity.publishingentity.accepted = True - group = DBSession.query(dbGroup).join(dbBaseGroup).filter( - dbBaseGroup.subject == 'lexical_entries_and_entities', - dbGroup.subject_override == True, - dbBaseGroup.action == 'create').one() - if user.is_active and user in group.users: + + tag_entity = dbEntity( + client_id = client.id, + field = field, + content = tag, + parent = lex) + + if create_flag: tag_entity.publishingentity.accepted = True # If we are the admin, we automatically publish link entities. @@ -396,7 +442,6 @@ def mutate(root, info, **args): return ConnectLexicalEntries(triumph=True) - class DeleteGroupingTags(graphene.Mutation): class Arguments: id = LingvodocID(required=True)