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

Added permissions for revoked membership #2016

Merged
merged 1 commit into from
Aug 15, 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
4 changes: 3 additions & 1 deletion met-api/src/met_api/models/engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,11 @@ def _filter_by_assigned_engagements(query, external_user_id: int, exception_stat
engagement_id
for engagement_id, in (
db.session.query(Engagement.id)
.join(MembershipModel)
.join(MembershipModel, MembershipModel.engagement_id == Engagement.id)
.join(StaffUser, StaffUser.external_id == external_user_id)
.filter(MembershipModel.user_id == StaffUser.id)
.filter(MembershipModel.is_latest.is_(True))
.filter(MembershipModel.status == MembershipStatus.ACTIVE.value)
.all()
)
]
Expand Down
10 changes: 9 additions & 1 deletion met-api/src/met_api/services/membership_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from met_api.services.staff_user_service import KEYCLOAK_SERVICE, StaffUserService
from met_api.utils.enums import KeycloakGroups, MembershipStatus
from met_api.utils.constants import Groups
from ..exceptions.business_exception import BusinessException
from met_api.services import authorization
from met_api.exceptions.business_exception import BusinessException
from met_api.utils.roles import Role


class MembershipService:
Expand Down Expand Up @@ -138,6 +140,12 @@ def update_membership_status(engagement_id: int, user_id: int, action: str):
if membership.engagement_id != int(engagement_id):
raise ValueError('Membership does not belong to this engagement.')

one_of_roles = (
MembershipType.TEAM_MEMBER.name,
Role.EDIT_MEMBERS.value
)
authorization.check_auth(one_of_roles=one_of_roles, engagement_id=engagement_id)

if not membership:
raise ValueError('Invalid Membership.')

Expand Down