Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduction of group management #1838

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions docs/samples/config/mscolab/mscolab_settings.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ STUB_CODE = """<?xml version="1.0" encoding="utf-8"?>
</ListOfWaypoints>
</FlightTrack>
"""

# looks for a given category forn a operation ending with GROUP_POSTFIX
# e.g. category = Tex will look for TexGroup
# all users in that Group are set to the operations of that category
# having the roles in the TexGroup
GROUP_POSTFIX = "Group"
7 changes: 7 additions & 0 deletions mslib/mscolab/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class default_mscolab_settings:
</ListOfWaypoints>
</FlightTrack>
"""

# looks for a given category forn a operation ending with GROUP_POSTFIX
# e.g. category = Tex will look for TexGroup
# all users in that Group are set to the operations of that category
# having the roles in the TexGroup
GROUP_POSTFIX = "Group"

enable_basic_http_authentication = False

# enable verification by Mail
Expand Down
39 changes: 39 additions & 0 deletions mslib/mscolab/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def create_operation(self, path, description, user, last_used=None, content=None
perm = Permission(user.id, operation_id, "creator")
db.session.add(perm)
db.session.commit()
# here we can import the permissions from Group file
if not path.endswith(mscolab_settings.GROUP_POSTFIX):
import_op = Operation.query.filter_by(path=f"{category}{mscolab_settings.GROUP_POSTFIX}").first()
if import_op is not None:
self.import_permissions(import_op.id, operation_id, user.id)
data = fs.open_fs(self.data_dir)
data.makedir(operation.path)
operation_file = data.open(fs.path.combine(operation.path, 'main.ftml'), 'w')
Expand Down Expand Up @@ -420,6 +425,17 @@ def add_bulk_permission(self, op_id, user, new_u_ids, access_level):
if Permission.query.filter_by(u_id=u_id, op_id=op_id).first() is None:
new_permissions.append(Permission(u_id, op_id, access_level))
db.session.add_all(new_permissions)
operation = Operation.query.filter_by(id=op_id).first()
if operation.path.endswith(mscolab_settings.GROUP_POSTFIX):
# the members of this gets added to all others of same category
category = operation.path.split(mscolab_settings.GROUP_POSTFIX)[0]
# all operation with that category
ops_category = Operation.query.filter_by(category=category)
new_permissions = []
for ops in ops_category:
if not ops.path.endswith(mscolab_settings.GROUP_POSTFIX):
new_permissions.append(Permission(u_id, ops.id, access_level))
db.session.add_all(new_permissions)
try:
db.session.commit()
return True
Expand All @@ -437,6 +453,17 @@ def modify_bulk_permission(self, op_id, user, u_ids, new_access_level):
.filter(Permission.u_id.in_(u_ids))\
.update({Permission.access_level: new_access_level}, synchronize_session='fetch')

operation = Operation.query.filter_by(id=op_id).first()
if operation.path.endswith(mscolab_settings.GROUP_POSTFIX):
# the members of this gets added to all others of same category
category = operation.path.split(mscolab_settings.GROUP_POSTFIX)[0]
# all operation with that category
ops_category = Operation.query.filter_by(category=category)
for ops in ops_category:
Permission.query \
.filter(Permission.op_id == ops.id) \
.filter(Permission.u_id.in_(u_ids)) \
.update({Permission.access_level: new_access_level}, synchronize_session='fetch')
try:
db.session.commit()
return True
Expand Down Expand Up @@ -467,6 +494,18 @@ def delete_bulk_permission(self, op_id, user, u_ids):
.filter(Permission.u_id.in_(u_ids)) \
.delete(synchronize_session='fetch')

operation = Operation.query.filter_by(id=op_id).first()
if operation.path.endswith(mscolab_settings.GROUP_POSTFIX):
# the members of this gets added to all others of same category
category = operation.path.split(mscolab_settings.GROUP_POSTFIX)[0]
# all operation with that category
ops_category = Operation.query.filter_by(category=category)
for ops in ops_category:
Permission.query \
.filter(Permission.op_id == ops.id) \
.filter(Permission.u_id.in_(u_ids)) \
.delete(synchronize_session='fetch')

db.session.commit()
return True

Expand Down