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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
632ee618
Commit
632ee618
authored
Feb 06, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prepare for backport
parent
61a1d1fc
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
102 deletions
+108
-102
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+2
-3
app/models/ee/user.rb
app/models/ee/user.rb
+0
-18
app/models/user.rb
app/models/user.rb
+18
-0
app/views/admin/users/_access_levels.html.haml
app/views/admin/users/_access_levels.html.haml
+10
-3
app/views/admin/users/_form.html.haml
app/views/admin/users/_form.html.haml
+1
-1
spec/models/user_spec.rb
spec/models/user_spec.rb
+77
-77
No files found.
app/controllers/admin/users_controller.rb
View file @
632ee618
...
@@ -175,7 +175,7 @@ class Admin::UsersController < Admin::ApplicationController
...
@@ -175,7 +175,7 @@ class Admin::UsersController < Admin::ApplicationController
def
user_params_ce
def
user_params_ce
[
[
:a
dmin
,
:a
ccess_level
,
:avatar
,
:avatar
,
:bio
,
:bio
,
:can_create_group
,
:can_create_group
,
...
@@ -203,8 +203,7 @@ class Admin::UsersController < Admin::ApplicationController
...
@@ -203,8 +203,7 @@ class Admin::UsersController < Admin::ApplicationController
def
user_params_ee
def
user_params_ee
[
[
:note
,
:note
:access_level
]
]
end
end
end
end
app/models/ee/user.rb
View file @
632ee618
...
@@ -36,23 +36,5 @@ module EE
...
@@ -36,23 +36,5 @@ module EE
def
admin_or_auditor?
def
admin_or_auditor?
admin?
||
auditor?
admin?
||
auditor?
end
end
def
access_level
if
admin?
:admin
elsif
auditor?
:auditor
else
:regular
end
end
def
access_level
=
(
new_level
)
new_level
=
new_level
.
to_s
return
unless
%w(admin auditor regular)
.
include?
(
new_level
)
self
.
admin
=
(
new_level
==
'admin'
)
self
.
auditor
=
(
new_level
==
'auditor'
)
end
end
end
end
end
app/models/user.rb
View file @
632ee618
...
@@ -934,6 +934,24 @@ class User < ActiveRecord::Base
...
@@ -934,6 +934,24 @@ class User < ActiveRecord::Base
Gitlab
::
UserActivities
::
ActivitySet
.
record
(
self
)
Gitlab
::
UserActivities
::
ActivitySet
.
record
(
self
)
end
end
def
access_level
if
admin?
:admin
elsif
auditor?
:auditor
else
:regular
end
end
def
access_level
=
(
new_level
)
new_level
=
new_level
.
to_s
return
unless
%w(admin auditor regular)
.
include?
(
new_level
)
self
.
admin
=
(
new_level
==
'admin'
)
self
.
auditor
=
(
new_level
==
'auditor'
)
end
private
private
def
ci_projects_union
def
ci_projects_union
...
...
app/views/admin/users/_access_levels
_ee
.html.haml
→
app/views/admin/users/_access_levels.html.haml
View file @
632ee618
...
@@ -11,22 +11,29 @@
...
@@ -11,22 +11,29 @@
.form-group
.form-group
=
f
.
label
:access_level
,
class:
'control-label'
=
f
.
label
:access_level
,
class:
'control-label'
.col-sm-10
.col-sm-10
=
f
.
radio_button
:access_level
,
:regular
,
disabled:
(
current_user
==
@user
&&
@user
.
is_admin?
)
-
editing_current_user
=
(
current_user
==
@user
)
=
f
.
radio_button
:access_level
,
:regular
,
disabled:
editing_current_user
=
label_tag
:regular
do
=
label_tag
:regular
do
Regular
Regular
%p
.light
%p
.light
Regular users have access to their groups and projects
Regular users have access to their groups and projects
-
if
license_allows_auditor_user?
-
if
license_allows_auditor_user?
=
f
.
radio_button
:access_level
,
:auditor
,
disabled:
(
current_user
==
@user
&&
@user
.
is_admin?
)
=
f
.
radio_button
:access_level
,
:auditor
,
disabled:
editing_current_user
=
label_tag
:auditor
do
=
label_tag
:auditor
do
Auditor
Auditor
%p
.light
%p
.light
Auditors have read-only access to all groups, projects and users
Auditors have read-only access to all groups, projects and users
=
f
.
radio_button
:access_level
,
:admin
=
f
.
radio_button
:access_level
,
:admin
,
disabled:
editing_current_user
=
label_tag
:admin
do
=
label_tag
:admin
do
Admin
Admin
%p
.light
%p
.light
Administrators have access to all groups, projects and users and can manage all features in this installation
Administrators have access to all groups, projects and users and can manage all features in this installation
-
if
editing_current_user
%p
.light
You cannot remove your own admin rights.
.form-group
.form-group
=
f
.
label
:external
,
class:
'control-label'
=
f
.
label
:external
,
class:
'control-label'
...
...
app/views/admin/users/_form.html.haml
View file @
632ee618
...
@@ -40,7 +40,7 @@
...
@@ -40,7 +40,7 @@
=
f
.
label
:password_confirmation
,
class:
'control-label'
=
f
.
label
:password_confirmation
,
class:
'control-label'
.col-sm-10
=
f
.
password_field
:password_confirmation
,
disabled:
f
.
object
.
force_random_password
,
class:
'form-control'
.col-sm-10
=
f
.
password_field
:password_confirmation
,
disabled:
f
.
object
.
force_random_password
,
class:
'form-control'
=
render
partial:
'access_levels
_ee
'
,
locals:
{
f:
f
}
=
render
partial:
'access_levels'
,
locals:
{
f:
f
}
%fieldset
%fieldset
%legend
Profile
%legend
Profile
...
...
spec/models/user_spec.rb
View file @
632ee618
...
@@ -1493,6 +1493,83 @@ describe User, models: true do
...
@@ -1493,6 +1493,83 @@ describe User, models: true do
end
end
end
end
describe
'#access_level='
do
let
(
:user
)
{
build
(
:user
)
}
before
do
# `auditor?` returns true only when the user is an auditor _and_ the auditor license
# add-on is present. We aren't testing this here, so we can assume that the add-on exists.
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
true
}
end
it
'does nothing for an invalid access level'
do
user
.
access_level
=
:invalid_access_level
expect
(
user
.
access_level
).
to
eq
(
:regular
)
expect
(
user
.
admin
).
to
be
false
expect
(
user
.
auditor
).
to
be
false
end
it
"assigns the 'admin' access level"
do
user
.
access_level
=
:admin
expect
(
user
.
access_level
).
to
eq
(
:admin
)
expect
(
user
.
admin
).
to
be
true
expect
(
user
.
auditor
).
to
be
false
end
it
"assigns the 'auditor' access level"
do
user
.
access_level
=
:auditor
expect
(
user
.
access_level
).
to
eq
(
:auditor
)
expect
(
user
.
admin
).
to
be
false
expect
(
user
.
auditor
).
to
be
true
end
it
"assigns the 'auditor' access level"
do
user
.
access_level
=
:regular
expect
(
user
.
access_level
).
to
eq
(
:regular
)
expect
(
user
.
admin
).
to
be
false
expect
(
user
.
auditor
).
to
be
false
end
it
"clears the 'admin' access level when a user is made an auditor"
do
user
.
access_level
=
:admin
user
.
access_level
=
:auditor
expect
(
user
.
access_level
).
to
eq
(
:auditor
)
expect
(
user
.
admin
).
to
be
false
expect
(
user
.
auditor
).
to
be
true
end
it
"clears the 'auditor' access level when a user is made an admin"
do
user
.
access_level
=
:auditor
user
.
access_level
=
:admin
expect
(
user
.
access_level
).
to
eq
(
:admin
)
expect
(
user
.
admin
).
to
be
true
expect
(
user
.
auditor
).
to
be
false
end
it
"doesn't clear existing access levels when an invalid access level is passed in"
do
user
.
access_level
=
:admin
user
.
access_level
=
:invalid_access_level
expect
(
user
.
access_level
).
to
eq
(
:admin
)
expect
(
user
.
admin
).
to
be
true
expect
(
user
.
auditor
).
to
be
false
end
it
"accepts string values in addition to symbols"
do
user
.
access_level
=
'admin'
expect
(
user
.
access_level
).
to
eq
(
:admin
)
expect
(
user
.
admin
).
to
be
true
expect
(
user
.
auditor
).
to
be
false
end
end
describe
'the GitLab_Auditor_User add-on'
do
describe
'the GitLab_Auditor_User add-on'
do
let
(
:license
)
{
build
(
:license
)
}
let
(
:license
)
{
build
(
:license
)
}
...
@@ -1551,82 +1628,5 @@ describe User, models: true do
...
@@ -1551,82 +1628,5 @@ describe User, models: true do
expect
(
build
(
:user
)).
not_to
be_auditor
expect
(
build
(
:user
)).
not_to
be_auditor
end
end
end
end
context
'access_level='
do
let
(
:user
)
{
build
(
:user
)
}
before
do
# `auditor?` returns true only when the user is an auditor _and_ the auditor license
# add-on is present. We aren't testing this here, so we can assume that the add-on exists.
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
true
}
end
it
'does nothing for an invalid access level'
do
user
.
access_level
=
:invalid_access_level
expect
(
user
.
access_level
).
to
eq
(
:regular
)
expect
(
user
.
admin
).
to
be
false
expect
(
user
.
auditor
).
to
be
false
end
it
"assigns the 'admin' access level"
do
user
.
access_level
=
:admin
expect
(
user
.
access_level
).
to
eq
(
:admin
)
expect
(
user
.
admin
).
to
be
true
expect
(
user
.
auditor
).
to
be
false
end
it
"assigns the 'auditor' access level"
do
user
.
access_level
=
:auditor
expect
(
user
.
access_level
).
to
eq
(
:auditor
)
expect
(
user
.
admin
).
to
be
false
expect
(
user
.
auditor
).
to
be
true
end
it
"assigns the 'auditor' access level"
do
user
.
access_level
=
:regular
expect
(
user
.
access_level
).
to
eq
(
:regular
)
expect
(
user
.
admin
).
to
be
false
expect
(
user
.
auditor
).
to
be
false
end
it
"clears the 'admin' access level when a user is made an auditor"
do
user
.
access_level
=
:admin
user
.
access_level
=
:auditor
expect
(
user
.
access_level
).
to
eq
(
:auditor
)
expect
(
user
.
admin
).
to
be
false
expect
(
user
.
auditor
).
to
be
true
end
it
"clears the 'auditor' access level when a user is made an admin"
do
user
.
access_level
=
:auditor
user
.
access_level
=
:admin
expect
(
user
.
access_level
).
to
eq
(
:admin
)
expect
(
user
.
admin
).
to
be
true
expect
(
user
.
auditor
).
to
be
false
end
it
"doesn't clear existing access levels when an invalid access level is passed in"
do
user
.
access_level
=
:admin
user
.
access_level
=
:invalid_access_level
expect
(
user
.
access_level
).
to
eq
(
:admin
)
expect
(
user
.
admin
).
to
be
true
expect
(
user
.
auditor
).
to
be
false
end
it
"accepts string values in addition to symbols"
do
user
.
access_level
=
'admin'
expect
(
user
.
access_level
).
to
eq
(
:admin
)
expect
(
user
.
admin
).
to
be
true
expect
(
user
.
auditor
).
to
be
false
end
end
end
end
end
end
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