Skip to content

Commit

Permalink
Merge pull request #1215 from myrix/heavy_refactor
Browse files Browse the repository at this point in the history
create entity accepted check fix
  • Loading branch information
myrix authored Nov 5, 2019
2 parents 7c95395 + b233403 commit d4ce292
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 29 deletions.
39 changes: 25 additions & 14 deletions lingvodoc/schema/gql_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
75 changes: 60 additions & 15 deletions lingvodoc/schema/gql_lexicalentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
import time
import string
import random
import logging


# Setting up logging.
log = logging.getLogger(__name__)


class LexicalEntry(LingvodocObjectType):
Expand Down Expand Up @@ -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) \
Expand All @@ -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.
Expand All @@ -396,7 +442,6 @@ def mutate(root, info, **args):
return ConnectLexicalEntries(triumph=True)



class DeleteGroupingTags(graphene.Mutation):
class Arguments:
id = LingvodocID(required=True)
Expand Down

0 comments on commit d4ce292

Please sign in to comment.