-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make role parsing tolerant to unknown roles
Where a role path in the db is not found in the current codebase, create a skeleton permissionless role instead of blowing up. This means we can remove role names from the python code and legacy entries in the db will no longer cause adverse effects. This supports finding of the old roles in (for example) a migration, but leaves these old unknown roles untouched unless they are explicitly acted on.
- Loading branch information
1 parent
551c7a8
commit ec33b2d
Showing
3 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,15 @@ | |
from django.urls import reverse | ||
from django.utils import timezone | ||
|
||
from jobserver.authorization.parsing import parse_roles | ||
from jobserver.authorization.roles import ( | ||
InteractiveReporter, | ||
OutputChecker, | ||
ProjectCollaborator, | ||
ProjectDeveloper, | ||
) | ||
from jobserver.models.user import User, get_or_create_user | ||
from jobserver.utils import dotted_path | ||
|
||
from ....factories import ( | ||
OrgFactory, | ||
|
@@ -351,3 +353,20 @@ def test_create_user(): | |
assert user.email == "[email protected]" | ||
# Password is not stored in plaintext. | ||
assert user.password != password | ||
|
||
|
||
def test_user_legacy_roles_round_trip(): | ||
roles = parse_roles(["jobserver.authorization.roles.LegacyRole"]) + [OutputChecker] | ||
user = UserFactory(roles=roles) | ||
user.save() | ||
user.refresh_from_db() | ||
|
||
assert {dotted_path(r) for r in user.roles} == {dotted_path(r) for r in roles} | ||
|
||
user.roles.append(ProjectCollaborator) | ||
user.save() | ||
user.refresh_from_db() | ||
|
||
assert {dotted_path(r) for r in user.roles} == { | ||
dotted_path(r) for r in roles + [ProjectCollaborator] | ||
} |