Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
db33c0fb
Commit
db33c0fb
authored
Jun 16, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensures default user limits when external user is unchecked
parent
537e60c0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
6 deletions
+45
-6
app/models/user.rb
app/models/user.rb
+9
-6
changelogs/unreleased/30725-reset-user-limits-when-unchecking-external-user.yml
...30725-reset-user-limits-when-unchecking-external-user.yml
+4
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+32
-0
No files found.
app/models/user.rb
View file @
db33c0fb
...
...
@@ -153,7 +153,7 @@ class User < ActiveRecord::Base
after_update
:update_emails_with_primary_email
,
if:
->
(
user
)
{
user
.
email_changed?
}
before_save
:ensure_authentication_token
,
:ensure_incoming_email_token
before_save
:ensure_
external_user_rights
before_save
:ensure_
user_rights_and_limits
,
if:
->
(
user
)
{
user
.
external_changed?
}
after_save
:ensure_namespace_correct
after_initialize
:set_projects_limit
after_destroy
:post_destroy_hook
...
...
@@ -1033,11 +1033,14 @@ class User < ActiveRecord::Base
super
end
def
ensure_external_user_rights
return
unless
external?
def
ensure_user_rights_and_limits
if
external?
self
.
can_create_group
=
false
self
.
projects_limit
=
0
else
self
.
can_create_group
=
true
self
.
projects_limit
=
current_application_settings
.
default_projects_limit
end
end
def
signup_domain_valid?
...
...
changelogs/unreleased/30725-reset-user-limits-when-unchecking-external-user.yml
0 → 100644
View file @
db33c0fb
---
title
:
Ensures default user limits when external user is unchecked
merge_request
:
12218
author
:
spec/models/user_spec.rb
View file @
db33c0fb
...
...
@@ -451,6 +451,38 @@ describe User, models: true do
end
end
describe
'#ensure_user_rights_and_limits'
do
describe
'with external user'
do
let
(
:user
)
{
create
(
:user
,
external:
true
)
}
it
'receives callback when external changes'
do
expect
(
user
).
to
receive
(
:ensure_user_rights_and_limits
)
user
.
update_attributes
(
external:
false
)
end
it
'ensures correct rights and limits for user'
do
expect
{
user
.
update_attributes
(
external:
false
)
}.
to
change
{
user
.
can_create_group
}.
to
(
true
)
.
and
change
{
user
.
projects_limit
}.
to
(
current_application_settings
.
default_projects_limit
)
end
end
describe
'without external user'
do
let
(
:user
)
{
create
(
:user
,
external:
false
)
}
it
'receives callback when external changes'
do
expect
(
user
).
to
receive
(
:ensure_user_rights_and_limits
)
user
.
update_attributes
(
external:
true
)
end
it
'ensures correct rights and limits for user'
do
expect
{
user
.
update_attributes
(
external:
true
)
}.
to
change
{
user
.
can_create_group
}.
to
(
false
)
.
and
change
{
user
.
projects_limit
}.
to
(
0
)
end
end
end
describe
'rss token'
do
it
'ensures an rss token on read'
do
user
=
create
(
:user
,
rss_token:
nil
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment