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 leaving the organization #6422

Merged
merged 22 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion cvat-core/src/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ Object.defineProperties(Organization.prototype.leave, {
const result = await serverProxy.organizations.members(this.slug, 1, 10, {
filter: JSON.stringify({
and: [{
'==': [{ var: 'user' }, user.id],
'==': [{ var: 'user' }, user.username],
nmanovic marked this conversation as resolved.
Show resolved Hide resolved
}],
}),
});
Expand Down
1 change: 1 addition & 0 deletions cvat-ui/src/actions/organization-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export function leaveOrganizationAsync(organization: any): ThunkAction {
await organization.leave(user);
dispatch(organizationActions.leaveOrganizationSuccess());
localStorage.removeItem('currentOrganization');
window.location.reload();
klakhov marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
dispatch(organizationActions.leaveOrganizationFailed(error));
}
Expand Down
11 changes: 9 additions & 2 deletions cvat/apps/iam/rules/memberships.rego
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ allow {
input.resource.organization.id == input.auth.organization.id
}

# maintainer of the organization can change role and delete all members except himself and owner
allow {
{ utils.CHANGE_ROLE, utils.DELETE }[input.scope]
input.resource.is_active
Expand All @@ -83,6 +84,7 @@ allow {
}[input.resource.role]
}

# owner of the organization can change role and delete all members except himself
allow {
{ utils.CHANGE_ROLE, utils.DELETE }[input.scope]
input.resource.is_active
Expand All @@ -92,11 +94,16 @@ allow {
input.resource.role != organizations.OWNER
}

# member can leave the organization except cases when member is the owner or maintainer
allow {
input.scope == utils.DELETE
input.resource.is_active
utils.is_sandbox
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirill-sizov, In case of deleting a membership, the environment will never be a sandbox. https://github.com/opencv/cvat/blob/9148234a159c5d5e193e1fcd785ed7010bf950b7/cvat/apps/iam/permissions.py#L61C29-L61C29

input.resource.role != organizations.OWNER
organizations.is_member
input.resource.organization.id == input.auth.organization.id
input.resource.user.id == input.auth.user.id
not {
organizations.OWNER,
organizations.MAINTAINER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marishka17 , why cannot maintainer leave the organization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nmanovic, For me, maintainer should also be able to leave the organization. But we have here and here such limitations..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea behind the rule was a maintainer cannot delete another maintainer. Maintainers should be possible to leave the organization for sure.

}[input.resource.role]
utils.has_perm(utils.WORKER)
}