Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
grady
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Jan Maximilian Michal
grady
Commits
a44cd339
Commit
a44cd339
authored
4 years ago
by
Dominik Seeger
Browse files
Options
Downloads
Patches
Plain Diff
Users now have a default group assigned if nothing else is specified
parent
7f9e5ccb
No related branches found
No related tags found
1 merge request
!240
Resolve "Add default group to every user that has no group"
Pipeline
#140947
failed
4 years ago
Stage: build
Stage: test
Changes
2
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/models/user_account.py
+12
-1
12 additions, 1 deletion
core/models/user_account.py
util/factories.py
+3
-2
3 additions, 2 deletions
util/factories.py
with
15 additions
and
3 deletions
core/models/user_account.py
+
12
−
1
View file @
a44cd339
...
...
@@ -38,6 +38,10 @@ class TutorReviewerManager(UserManager):
assignment_model
.
FEEDBACK_VALIDATION
))
def
group_default
():
return
[
Group
.
objects
.
get_or_create
(
name
=
"
Default Group
"
)[
0
].
pk
]
class
UserAccount
(
AbstractUser
):
"""
An abstract base class implementing a fully featured User model with
...
...
@@ -64,7 +68,8 @@ class UserAccount(AbstractUser):
exercise_groups
=
models
.
ManyToManyField
(
Group
,
blank
=
True
,
related_name
=
'
users
'
)
related_name
=
'
users
'
,
default
=
group_default
)
fullname
=
models
.
CharField
(
'
full name
'
,
max_length
=
70
,
blank
=
True
)
is_admin
=
models
.
BooleanField
(
default
=
False
)
...
...
@@ -83,6 +88,12 @@ class UserAccount(AbstractUser):
def
is_reviewer
(
self
):
return
self
.
role
==
'
Reviewer
'
def
set_groups
(
self
,
groups
):
if
groups
==
[]
or
groups
is
None
:
self
.
exercise_groups
.
set
(
group_default
())
else
:
self
.
exercise_groups
.
set
(
groups
)
# All of these methods are deprecated and should be replaced by custom
# Managers (see tutor manager)
@classmethod
...
...
This diff is collapsed.
Click to expand it.
util/factories.py
+
3
−
2
View file @
a44cd339
...
...
@@ -76,13 +76,14 @@ class GradyUserFactory:
role
=
role
,
defaults
=
kwargs
)
exercise_groups
=
[]
if
exercise_groups
is
None
else
exercise_groups
if
exercise_groups
is
None
:
exercise_groups
=
[]
groups_in_db
=
[]
for
group
in
exercise_groups
:
groups_in_db
.
append
(
Group
.
objects
.
get_or_create
(
name
=
group
)[
0
].
pk
)
user
.
exerci
se_groups
.
set
(
groups_in_db
)
user
.
se
t
_groups
(
groups_in_db
)
if
created
or
password
is
not
None
:
password
=
self
.
make_password
()
if
password
is
None
else
password
...
...
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