-
Notifications
You must be signed in to change notification settings - Fork 168
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
Add violations backend code #447
Conversation
4c2260b
to
6f8a3a7
Compare
class ProjectViolationsClearApiView(APIView): | ||
""" | ||
Clear all violations for a project | ||
|
||
Requires authentication and owner. | ||
Returns project details. | ||
""" | ||
|
||
permission_classes = [IsAuthenticated, IsOwner] | ||
throttle_classes = [CustomUserRateThrottle, SustainedRateThrottle] | ||
|
||
def post(self, request, *, pk): | ||
try: | ||
old = Project.objects.get(pk=pk) | ||
except Project.DoesNotExist: | ||
return Response('Not found', status=404) | ||
|
||
if not request.user or old.creator.id != request.user.id: | ||
return Response('Error', status=403) | ||
|
||
old.violations.set([]) | ||
old.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we add this functionality to the update function in the ProjectSerializer
? This would also prevent the user from having to make two api calls on the frontend when updating a project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but I feel like that's going to be replaced pretty quickly in the future when actual moderation is implemented. This system is more extensible imo. I feel like 2 API calls isn't much of a problem, but I can replace this if we're sure.
class ProjectViolationAddApiView(CreateAPIView): | ||
""" | ||
Creates a new violation and adds it to a project. | ||
|
||
Requires authentication and staff or moderator. | ||
Returns the violation details. | ||
""" | ||
queryset = Violation.objects.all() | ||
serializer_class = ViolationSerializer | ||
permission_classes = [IsAuthenticated, IsStaffOrModerator] | ||
throttle_classes = [PostUserRateThrottle, SustainedRateThrottle] | ||
|
||
def perform_create(self, serializer): | ||
pk = self.kwargs.get("pk") | ||
project = Project.objects.get(id=pk) | ||
violation = serializer.save(creator=self.request.user, project=project) | ||
project.violations.add(violation) | ||
project.save() | ||
return violation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Send notification to user to let them know their project was unpublished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we need a new notification type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
Can you also pre-load the |
* Init * Unpublish project form (#452) * Lay out structure * Make progress * Style menu * Style checkboxes & buttons * Add api call * Make mobile-friendly * Last styling changes * Address styling comments * Remove for non-staff & non-moderators * Add violations backend code (#447) * Add violations backend system * Fix typo * Add new migrations * Basic * Use array * Fix issuesgit status * Swap fetch parameter * Add responses * Add new violation ui for violation notifications * Fix models Co-authored-by: Aditya Jain <[email protected]> * Unpublished Project Modal (#446) * set up modal * style changes * change to label and mobile styles * tiny fix of class style * scrolling * tiny style fix * clean up unused things * overflow scroll bar adjustments * Small style * remove important Co-authored-by: Aditya Jain <[email protected]> * Integrate Co-authored-by: Grace Zhang <[email protected]> Co-authored-by: Andrew Lester <[email protected]> Co-authored-by: Zora Zhang <[email protected]>
* Init * Unpublish project form (#452) * Lay out structure * Make progress * Style menu * Style checkboxes & buttons * Add api call * Make mobile-friendly * Last styling changes * Address styling comments * Remove for non-staff & non-moderators * Add violations backend code (#447) * Add violations backend system * Fix typo * Add new migrations * Basic * Use array * Fix issuesgit status * Swap fetch parameter * Add responses * Add new violation ui for violation notifications * Fix models Co-authored-by: Aditya Jain <[email protected]> * Unpublished Project Modal (#446) * set up modal * style changes * change to label and mobile styles * tiny fix of class style * scrolling * tiny style fix * clean up unused things * overflow scroll bar adjustments * Small style * remove important Co-authored-by: Aditya Jain <[email protected]> * Integrate Co-authored-by: Grace Zhang <[email protected]> Co-authored-by: Andrew Lester <[email protected]> Co-authored-by: Zora Zhang <[email protected]>
Summary
Closes: #428
Changes
Requests / Responses
GET `/projects/violation-reasons` Returns violation reasons
Response
PUT `/projects/:uuid/clear-violations` Clears a project's violations
Request
No body
Response
"Success"
POST `/projects/:uuid/add-violation` Adds a violation
Request
Response