activist icon indicating copy to clipboard operation
activist copied to clipboard

Custom permissions for Group API write operations

Open to-sta opened this issue 7 months ago • 2 comments

Terms

Description

It would make sense to start implement custom permission for our API. At the moment we are using IsAuthenticatedOrReadOnly for GroupDetailAPIView. But for all write operations (PUT, PATCH, DELETE) we also have to check if the request user is the creator of the group or is admin or staff.

This is how it is done currently:

 if request.user != org.created_by and not request.user.is_staff:
    return Response(
                {"error": "You are not authorized to update this organization"},
                status=status.HTTP_401_UNAUTHORIZED,
            )

And we should implement something like this with BasePermissions:

class IsAdminStaffCreatorOrReadOnly(BasePermissions)
    ...

Contribution

to-sta avatar Apr 20 '25 06:04 to-sta

I am willing to be assigned!

ChuqiaoHuang avatar Apr 20 '25 23:04 ChuqiaoHuang

Thanks for your interest in helping out here, @ChuqiaoHuang! Please let us know if you need any support :)

andrewtavis avatar Apr 21 '25 06:04 andrewtavis

hey @andrewtavis can i work on this issue?

rohityadav2604 avatar May 02 '25 11:05 rohityadav2604

Adding @rohityadav2604 to the assignees here :) Please let us know if you've already started working on this, @ChuqiaoHuang! 😊

andrewtavis avatar May 02 '25 11:05 andrewtavis

Feel free to get started in the meantime and maybe we can combine implementations, @rohityadav2604 :)

andrewtavis avatar May 02 '25 11:05 andrewtavis

thankyou @andrewtavis i will start working on this. @ChuqiaoHuang if you have started working on it. let me know the progress we can divide the task accordingly.

rohityadav2604 avatar May 02 '25 11:05 rohityadav2604

Closed by #1287 🚀 Thanks so much for taking this on and for the quality contribution, @rohityadav2604! Looking forward to the next one! 😊

andrewtavis avatar Jun 01 '25 13:06 andrewtavis