Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
2cc4523c
Commit
2cc4523c
authored
3 years ago
by
Tore.Brede
Browse files
Options
Downloads
Patches
Plain Diff
GREG-85: Rejecting request if user tries to update fields he is not allowed to
parent
5535c701
No related branches found
No related tags found
1 merge request
!113
GREG-85: Guest registration page
Pipeline
#97483
failed
3 years ago
Stage: venv update
Stage: tests and linting
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gregui/api/views/invitation.py
+15
-1
15 additions, 1 deletion
gregui/api/views/invitation.py
with
15 additions
and
1 deletion
gregui/api/views/invitation.py
+
15
−
1
View file @
2cc4523c
...
@@ -103,10 +103,14 @@ class CheckInvitationView(APIView):
...
@@ -103,10 +103,14 @@ class CheckInvitationView(APIView):
class
InvitedGuestView
(
GenericAPIView
):
class
InvitedGuestView
(
GenericAPIView
):
authentication_classes
=
[
SessionAuthentication
,
BasicAuthentication
]
authentication_classes
=
[
SessionAuthentication
,
BasicAuthentication
]
# The endpoint is only for invited guests, but the authorization happens in the actual method
permission_classes
=
[
AllowAny
]
permission_classes
=
[
AllowAny
]
parser_classes
=
[
JSONParser
]
parser_classes
=
[
JSONParser
]
serializer_class
=
GuestRegisterSerializer
serializer_class
=
GuestRegisterSerializer
# TODO Update to make dynamic based on where we get the information from. If we get some from Feide, then the user should not be allowed to change it
fields_allowed_to_update
=
[
"
email
"
,
"
fnr
"
,
"
mobile_phone
"
]
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
"""
"""
Endpoint for fetching data related to an invite
Endpoint for fetching data related to an invite
...
@@ -172,7 +176,6 @@ class InvitedGuestView(GenericAPIView):
...
@@ -172,7 +176,6 @@ class InvitedGuestView(GenericAPIView):
the guest.
the guest.
"""
"""
invite_id
=
request
.
session
.
get
(
"
invite_id
"
)
invite_id
=
request
.
session
.
get
(
"
invite_id
"
)
data
=
request
.
data
# Ensure the invitation link is valid and not expired
# Ensure the invitation link is valid and not expired
try
:
try
:
...
@@ -184,6 +187,11 @@ class InvitedGuestView(GenericAPIView):
...
@@ -184,6 +187,11 @@ class InvitedGuestView(GenericAPIView):
person
=
invite_link
.
invitation
.
role
.
person
person
=
invite_link
.
invitation
.
role
.
person
data
=
request
.
data
if
not
self
.
only_allowed_fields_in_request
(
data
):
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
with
transaction
.
atomic
():
with
transaction
.
atomic
():
serializer
=
self
.
get_serializer
(
instance
=
person
,
data
=
request
.
data
)
serializer
=
self
.
get_serializer
(
instance
=
person
,
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
serializer
.
is_valid
(
raise_exception
=
True
)
...
@@ -198,3 +206,9 @@ class InvitedGuestView(GenericAPIView):
...
@@ -198,3 +206,9 @@ class InvitedGuestView(GenericAPIView):
invite_link
.
save
()
invite_link
.
save
()
# TODO: Send an email to the sponsor?
# TODO: Send an email to the sponsor?
return
Response
(
status
=
status
.
HTTP_200_OK
)
return
Response
(
status
=
status
.
HTTP_200_OK
)
def
only_allowed_fields_in_request
(
self
,
request_data
)
->
bool
:
number_of_fields_filled_in
=
sum
(
map
(
lambda
x
:
x
in
request_data
.
keys
(),
self
.
fields_allowed_to_update
)
)
return
number_of_fields_filled_in
==
len
(
request_data
.
keys
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment