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

Fix Possible Member Duplication #7804

Merged
merged 3 commits into from Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/7804.bugfix
@@ -0,0 +1 @@
Aligned `member_create` with `group_member_save` to prevent possible member duplication.
7 changes: 6 additions & 1 deletion ckan/logic/action/create.py
Expand Up @@ -612,7 +612,10 @@ def member_create(context: Context,
filter(model.Member.table_name == obj_type).\
filter(model.Member.table_id == obj.id).\
filter(model.Member.group_id == group.id).\
filter(model.Member.state == 'active').first()
order_by(
# type_ignore_reason: incomplete SQLAlchemy types
model.Member.state.asc() # type: ignore
).first()
if member:
user_obj = model.User.get(user)
if user_obj and member.table_name == u'user' and \
Expand All @@ -621,6 +624,8 @@ def member_create(context: Context,
capacity != u'admin':
raise NotAuthorized("Administrators cannot revoke their "
"own admin status")
if member.state != u'active':
member.state = u'active'
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
else:
member = model.Member(table_name=obj_type,
table_id=obj.id,
Expand Down