Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
47cc43f6
Commit
47cc43f6
authored
3 years ago
by
Shrikrishna Singh
Browse files
Options
Downloads
Patches
Plain Diff
Fix api permissions
parent
2a0f33ba
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hypha/apply/api/v1/permissions.py
+15
-8
15 additions, 8 deletions
hypha/apply/api/v1/permissions.py
hypha/apply/api/v1/projects/views.py
+8
-6
8 additions, 6 deletions
hypha/apply/api/v1/projects/views.py
with
23 additions
and
14 deletions
hypha/apply/api/v1/permissions.py
+
15
−
8
View file @
47cc43f6
...
...
@@ -20,19 +20,26 @@ class IsApplyStaffUser(permissions.BasePermission):
class
IsFinance1User
(
permissions
.
BasePermission
):
def
has_permission
(
self
,
request
,
view
):
invoice
=
view
.
get_invoice_object
()
return
request
.
user
.
is_finance_level_1
and
invoice
.
can_user_edit_deliverables
(
request
.
user
)
return
request
.
user
.
is_finance_level_1
def
has_object_permission
(
self
,
request
,
view
,
obj
):
invoice
=
view
.
get_invoice_object
()
return
request
.
user
.
is_finance_level_1
and
invoice
.
can_user_edit_deliverables
(
request
.
user
)
return
request
.
user
.
is_finance_level_1
class
IsFinance2User
(
permissions
.
BasePermission
):
def
has_permission
(
self
,
request
,
view
):
invoice
=
view
.
get_invoice_object
()
return
request
.
user
.
is_finance_level_2
and
invoice
.
can_user_edit_deliverables
(
request
.
user
)
return
request
.
user
.
is_finance_level_2
def
has_object_permission
(
self
,
request
,
view
,
obj
):
return
request
.
user
.
is_finance_level_2
class
HasDeliverableEditPermission
(
permissions
.
BasePermission
):
def
has_permission
(
self
,
request
,
view
):
invoice
=
view
.
get_invoice_object
()
return
request
.
user
.
is_finance_level_2
and
invoice
.
can_user_edit_deliverables
(
request
.
user
)
return
invoice
.
can_user_edit_deliverables
(
request
.
user
)
class
HasRequiredChecksPermission
(
permissions
.
BasePermission
):
def
has_permission
(
self
,
request
,
view
):
invoice
=
view
.
get_object
()
return
invoice
.
can_user_complete_required_checks
(
request
.
user
)
This diff is collapsed.
Click to expand it.
hypha/apply/api/v1/projects/views.py
+
8
−
6
View file @
47cc43f6
...
...
@@ -9,7 +9,11 @@ from hypha.apply.projects.models.payment import Invoice, InvoiceDeliverable
from
hypha.apply.projects.models.project
import
Deliverable
from
..mixin
import
InvoiceNestedMixin
,
ProjectNestedMixin
from
..permissions
import
IsApplyStaffUser
,
IsFinance1User
,
IsFinance2User
from
..permissions
import
(
IsApplyStaffUser
,
IsFinance1User
,
IsFinance2User
,
HasDeliverableEditPermission
,
HasRequiredChecksPermission
)
from
.serializers
import
(
DeliverableSerializer
,
InvoiceDeliverableListSerializer
,
...
...
@@ -25,7 +29,8 @@ class DeliverableViewSet(
viewsets
.
GenericViewSet
):
permission_classes
=
(
permissions
.
IsAuthenticated
,
IsApplyStaffUser
|
IsFinance1User
|
IsFinance2User
permissions
.
IsAuthenticated
,
HasDeliverableEditPermission
,
IsApplyStaffUser
|
IsFinance1User
|
IsFinance2User
)
serializer_class
=
InvoiceDeliverableListSerializer
pagination_class
=
None
...
...
@@ -81,12 +86,9 @@ class InvoiceRequiredChecksViewSet(
viewsets
.
GenericViewSet
,
):
serializer_class
=
InvoiceRequiredChecksSerializer
permission_classes
=
[
IsFinance1User
]
permission_classes
=
[
IsFinance1User
,
HasRequiredChecksPermission
]
queryset
=
Invoice
.
objects
.
all
()
def
get_invoice_object
(
self
):
return
self
.
get_object
()
@action
(
detail
=
True
,
methods
=
[
'
post
'
])
def
set_required_checks
(
self
,
request
,
*
args
,
**
kwargs
):
serializer
=
self
.
get_serializer
(
data
=
request
.
data
)
...
...
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