Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iric-data
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
Container Registry
Model registry
Operate
Environments
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
bioinfo_iric
iric-data
Commits
c1f1389b
Commit
c1f1389b
authored
2 years ago
by
LouisGendron
Browse files
Options
Downloads
Patches
Plain Diff
Pass request user to DataSetForm is_valid func
parent
60d2aab6
Branches
174-fix-dataset-modifications-by-graphql
Branches containing commit
No related tags found
1 merge request
!97
Resolve "Fix DataSet modifications by graphql"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
portal/forms.py
+16
-0
16 additions, 0 deletions
portal/forms.py
portal/graphql_schema.py
+1
-0
1 addition, 0 deletions
portal/graphql_schema.py
portal/views/secure/dataset.py
+10
-0
10 additions, 0 deletions
portal/views/secure/dataset.py
with
27 additions
and
0 deletions
portal/forms.py
+
16
−
0
View file @
c1f1389b
...
...
@@ -257,6 +257,8 @@ class BatchDeleteDataFileForm(forms.Form):
class
DataSetForm
(
forms
.
ModelForm
):
request_profile
=
None
class
Meta
:
model
=
DataSet
fields
=
(
'
name
'
,
'
share_profiles
'
,
'
share_labs
'
,
'
share_groups
'
,
'
files
'
,
'
read_only
'
)
...
...
@@ -268,6 +270,20 @@ class DataSetForm(forms.ModelForm):
'
files
'
:
_
(
'
Files
'
)
}
def
__init__
(
self
,
*
args
,
**
kwargs
):
request_profile
=
kwargs
.
pop
(
'
request_profile
'
,
None
)
if
request_profile
:
self
.
request_profile
=
request_profile
super
().
__init__
(
*
args
,
**
kwargs
)
def
is_valid
(
self
)
->
bool
:
is_valid
=
super
().
is_valid
()
if
not
is_valid
:
return
is_valid
elif
self
.
instance
.
id
:
# Apply only to DS update
is_valid
=
self
.
instance
in
DataSet
.
objects
.
writable_by_profile
(
self
.
request_profile
)
return
is_valid
class
DataSetDisplayFieldsForm
(
forms
.
ModelForm
):
options
=
forms
.
MultipleChoiceField
(
...
...
This diff is collapsed.
Click to expand it.
portal/graphql_schema.py
+
1
−
0
View file @
c1f1389b
...
...
@@ -200,6 +200,7 @@ class DataSetMutation(DjangoModelFormMutation):
@classmethod
def
get_form_kwargs
(
cls
,
root
,
info
,
**
input
)
->
dict
:
kwargs
=
super
().
get_form_kwargs
(
root
,
info
,
**
input
)
kwargs
[
'
request_profile
'
]
=
info
.
context
.
user
.
profile
if
'
read_only
'
not
in
kwargs
[
'
data
'
]
and
'
instance
'
not
in
kwargs
.
keys
():
kwargs
[
'
data
'
][
'
read_only
'
]
=
True
return
kwargs
...
...
This diff is collapsed.
Click to expand it.
portal/views/secure/dataset.py
+
10
−
0
View file @
c1f1389b
...
...
@@ -138,6 +138,11 @@ class DataSetCreateView(LoginRequiredMixin, CreateViewMixin, CreateView):
active_page
=
'
datasets
'
template_name
=
'
portal/secure/user/create_update.html
'
def
get_form_kwargs
(
self
):
kwargs
=
super
().
get_form_kwargs
()
kwargs
.
update
({
'
request_profile
'
:
self
.
request
.
user
.
profile
})
return
kwargs
def
get_form
(
self
,
form_class
=
None
):
form
=
super
().
get_form
(
form_class
)
form
.
fields
[
'
share_profiles
'
].
queryset
=
Profile
.
objects
.
exclude_profile
(
self
.
request
.
user
.
profile
)
...
...
@@ -165,6 +170,11 @@ class DataSetUpdateView(DataSetLogMixin, LoginRequiredMixin, UpdateViewMixin, Up
active_page
=
'
datasets
'
template_name
=
'
portal/secure/user/create_update.html
'
def
get_form_kwargs
(
self
):
kwargs
=
super
().
get_form_kwargs
()
kwargs
.
update
({
'
request_profile
'
:
self
.
request
.
user
.
profile
})
return
kwargs
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
().
get_context_data
(
**
kwargs
)
context
[
'
warning_msg
'
]
=
_
(
'
You are about to modify this DataSet. If you are not its original owner, please make sure that you have permission to perform this action.
'
)
...
...
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