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

Move group membership views into their own file #9113

Merged
merged 5 commits into from
Nov 26, 2024
Merged

Conversation

seanh
Copy link
Contributor

@seanh seanh commented Nov 22, 2024

...plus a little tidy up.

I wanted to also tidy them up into a nice view class but I don't think that's going to be possible without first doing a bunch of work to remove h's custom @api_config decorator (Slack thread). Not worth the effort right now, it's fine how it is. But if it wasn't for @api_config it would be possible to do something like this:

@view_config(
    route_name="api.group_members",
    request_method="GET",
    permission=Permission.Group.READ,
)
def list_members(context: GroupContext, _request):
    return [UserJSONPresenter(user).asdict() for user in context.group.members]


@view_defaults(route_name="api.group_members")
class GroupMembershipAPIViews:
    def __init__(self, context: GroupMembershipContext, request: Request):
        self.context = context
        self.group_members_service = request.find_service(name="group_members")

    @view_config(request_method="DELETE", permission=Permission.Group.MEMBER_REMOVE)
    def delete(self):
        self.group_members_service.member_leave(context.group, context.user.userid)
        return HTTPNoContent()

    @view_config(request_method="POST", permission=Permission.Group.MEMBER_ADD)
    def post(self):
        if context.user.authority != context.group.authority:
            raise HTTPNotFound()

        self.group_members_service.member_join(context.group, context.user.userid)
        return HTTPNoContent()

    @view_config(request_method="PATCH", permission=Permission.Group.MEMBER_EDIT)
    def patch(self):
        ...

    @view_config(request_method="GET", permission=Permission.Group.READ)
    def get(self):
        ...

@seanh seanh requested a review from marcospri November 22, 2024 19:08
@seanh seanh changed the title add edit membership api Move group membership views into their own file Nov 22, 2024
Base automatically changed from extend-remove-member-api to main November 26, 2024 13:14
Group membership views and group views are not really the same thing and
it's not very nice to group them all together in one big file. We
already have a separate `services/group_members.py` and a separate
`traversal/group_membership.py`, move the group membership views into
a separate `views/api/group_members.py` as well.
Improve the descriptions and docstrings on these API views.

Make the order of the six `@api_config()` arguments consistent across
the three views.

Remove `is_authenticated=True`: this is not needed when `permission` is
used.

Make the group_members_service / group_members_svc variable name
consistent.
@seanh seanh merged commit 6a0dc32 into main Nov 26, 2024
9 checks passed
@seanh seanh deleted the add-edit-membership-api branch November 26, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants