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
bf60c66b
Commit
bf60c66b
authored
3 years ago
by
Tore.Brede
Browse files
Options
Downloads
Patches
Plain Diff
GREG-91: Setting hierarchical access by default to false
parent
1856b17e
No related branches found
No related tags found
1 merge request
!126
GREG-91: Expand sponsor api
Pipeline
#98526
passed
3 years ago
Stage: venv update
Stage: tests and linting
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
greg/api/views/sponsor.py
+2
-2
2 additions, 2 deletions
greg/api/views/sponsor.py
greg/tests/api/test_sponsor.py
+47
-4
47 additions, 4 deletions
greg/tests/api/test_sponsor.py
with
49 additions
and
6 deletions
greg/api/views/sponsor.py
+
2
−
2
View file @
bf60c66b
...
...
@@ -79,7 +79,8 @@ class SponsorOrgunitLinkView(
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
(
sponsor_id
,
orgunit_id
)
=
self
.
_extract_sponsor_and_orgunit
(
kwargs
)
hierarchical_access
=
request
.
data
.
get
(
"
hierarchical_access
"
)
# Default to false if hierarchical_access is not specified
hierarchical_access
=
request
.
data
.
get
(
"
hierarchical_access
"
,
"
False
"
)
sponsor
=
Sponsor
.
objects
.
get
(
id
=
sponsor_id
)
sponsor
.
units
.
add
(
orgunit_id
,
through_defaults
=
{
"
hierarchical_access
"
:
hierarchical_access
}
...
...
@@ -92,7 +93,6 @@ class SponsorOrgunitLinkView(
but the link between the sponsor and the unit
"""
(
sponsor_id
,
orgunit_id
)
=
self
.
_extract_sponsor_and_orgunit
(
kwargs
)
sponsor
=
Sponsor
.
objects
.
filter
(
id
=
sponsor_id
).
get
()
sponsor
.
units
.
remove
(
orgunit_id
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
...
...
This diff is collapsed.
Click to expand it.
greg/tests/api/test_sponsor.py
+
47
−
4
View file @
bf60c66b
...
...
@@ -3,7 +3,13 @@ from rest_framework import status
from
rest_framework.reverse
import
reverse
from
greg.models
import
OrganizationalUnit
,
Sponsor
,
Person
,
Identity
from
greg.models
import
(
OrganizationalUnit
,
Sponsor
,
Person
,
Identity
,
SponsorOrganizationalUnit
,
)
@pytest.mark.django_db
...
...
@@ -66,14 +72,14 @@ def test_add_sponsor_with_unit(client, unit_foo: OrganizationalUnit):
assert
len
(
sponsor_lookup_response_body
[
"
results
"
])
==
1
assert
len
(
sponsor_lookup_response_body
[
"
results
"
][
0
][
"
units
"
])
==
0
data
=
{
"
hierarchical_access
"
:
"
t
rue
"
}
data
=
{
"
hierarchical_access
"
:
"
T
rue
"
}
create_sponsor_link_url
=
reverse
(
"
v1:sponsor_orgunit-detail
"
,
kwargs
=
{
"
sponsor_id
"
:
sponsor_id
,
"
orgunit_id
"
:
unit_foo
.
id
},
)
response
=
client
.
post
(
create_sponsor_link_url
,
data
=
data
)
assert
response
.
status_code
==
status
.
HTTP_20
0_OK
assert
response
.
status_code
==
status
.
HTTP_20
4_NO_CONTENT
sponsor_lookup_response
=
client
.
get
(
sponsor_url
,
kwargs
=
{
"
id
"
:
sponsor_id
})
sponsor_lookup_response_body
=
sponsor_lookup_response
.
json
()
...
...
@@ -91,7 +97,7 @@ def test_remove_sponsor_orgunit_link(
response_get
=
client
.
get
(
sponsor_detail_url
).
json
()
assert
len
(
response_get
[
"
units
"
])
==
0
data
=
{
"
hierarchical_access
"
:
True
}
data
=
{
"
hierarchical_access
"
:
"
True
"
}
sponsor_orgunit_url
=
reverse
(
"
v1:sponsor_orgunit-detail
"
,
...
...
@@ -144,3 +150,40 @@ def test_delete_sponsor_connected_to_identity_not_allowed(
# Check that the sponsor has been deleted
response_get
=
client
.
get
(
sponsor_detail_url
)
assert
response_get
.
status_code
==
status
.
HTTP_404_NOT_FOUND
@pytest.mark.django_db
def
test_add_sponsor_unit_link_with_no_access_parameter
(
client
,
unit_foo
:
OrganizationalUnit
):
sponsor_url
=
reverse
(
"
v1:sponsor-list
"
)
data
=
{
"
feide_id
"
:
"
sponsor@example.org
"
,
"
first_name
"
:
"
Test
"
,
"
last_name
"
:
"
Sponsor
"
,
}
response
=
client
.
post
(
sponsor_url
,
data
=
data
)
sponsor_id
=
response
.
json
()[
"
id
"
]
# Do a post with no data
create_sponsor_link_url
=
reverse
(
"
v1:sponsor_orgunit-detail
"
,
kwargs
=
{
"
sponsor_id
"
:
sponsor_id
,
"
orgunit_id
"
:
unit_foo
.
id
},
)
response
=
client
.
post
(
create_sponsor_link_url
)
assert
response
.
status_code
==
status
.
HTTP_204_NO_CONTENT
# Check that the unit is attached to the sponsor
sponsor_lookup_response
=
client
.
get
(
sponsor_url
,
kwargs
=
{
"
id
"
:
sponsor_id
})
sponsor_lookup_response_body
=
sponsor_lookup_response
.
json
()
assert
len
(
sponsor_lookup_response_body
[
"
results
"
][
0
][
"
units
"
])
==
1
attached_unit
=
sponsor_lookup_response_body
[
"
results
"
][
0
][
"
units
"
][
0
]
assert
attached_unit
[
"
id
"
]
==
unit_foo
.
id
# Check that hierarchical_access is set to False for the link between the sponsor and unit
sponsor_organization_unit
=
SponsorOrganizationalUnit
.
objects
.
filter
(
sponsor_id
=
sponsor_id
,
organizational_unit_id
=
unit_foo
.
id
).
get
()
assert
not
sponsor_organization_unit
.
hierarchical_access
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