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

permissions added #336

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion project_rates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ProjectScoreCreateSerializer,
ProjectScoreGetSerializer,
)
from users.models import Expert
from users.permissions import IsExpert, IsExpertPost

User = get_user_model()
Expand All @@ -33,6 +34,9 @@ def get_needed_data(self) -> tuple[dict, list[int]]:
criteria_to_get = [
criterion["criterion_id"] for criterion in data
] # is needed for validation later

Expert.objects.get(user__id=user_id, programs__criterias__id=criteria_to_get[0])

for criterion in data:
criterion["user"] = user_id
criterion["project"] = project_id
Expand All @@ -57,7 +61,11 @@ def create(self, request, *args, **kwargs) -> Response:
)

return Response({"success": True}, status=status.HTTP_201_CREATED)

except Expert.DoesNotExist:
return Response(
{"error": "you have no permission to rate this program"},
status=status.HTTP_403_FORBIDDEN,
)
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST)

Expand Down
Loading