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
Show 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,66 +1493,7 @@ describe User, models: true do
...
@@ -1493,66 +1493,7 @@ describe User, models: true do
end
end
end
end
describe
'the GitLab_Auditor_User add-on'
do
describe
'#access_level='
do
let
(
:license
)
{
build
(
:license
)
}
before
do
allow
(
::
License
).
to
receive
(
:current
).
and_return
(
license
)
end
context
'creating an auditor user'
do
it
"does not allow creating an auditor user if the addon isn't enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
false
}
expect
(
build
(
:user
,
:auditor
)).
to
be_invalid
end
it
"does not allow creating an auditor user if no license is present"
do
allow
(
License
).
to
receive
(
:current
).
and_return
nil
expect
(
build
(
:user
,
:auditor
)).
to
be_invalid
end
it
"allows creating an auditor user if the addon is enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
true
}
expect
(
build
(
:user
,
:auditor
)).
to
be_valid
end
it
"allows creating a regular user if the addon isn't enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
false
}
expect
(
build
(
:user
)).
to
be_valid
end
end
context
'#auditor?'
do
it
"returns true for an auditor user if the addon is enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
true
}
expect
(
build
(
:user
,
:auditor
)).
to
be_auditor
end
it
"returns false for an auditor user if the addon is not enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
false
}
expect
(
build
(
:user
,
:auditor
)).
not_to
be_auditor
end
it
"returns false for an auditor user if a license is not present"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
false
}
expect
(
build
(
:user
,
:auditor
)).
not_to
be_auditor
end
it
"returns false for a non-auditor user even if the addon is present"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
true
}
expect
(
build
(
:user
)).
not_to
be_auditor
end
end
context
'access_level='
do
let
(
:user
)
{
build
(
:user
)
}
let
(
:user
)
{
build
(
:user
)
}
before
do
before
do
...
@@ -1628,5 +1569,64 @@ describe User, models: true do
...
@@ -1628,5 +1569,64 @@ describe User, models: true do
expect
(
user
.
auditor
).
to
be
false
expect
(
user
.
auditor
).
to
be
false
end
end
end
end
describe
'the GitLab_Auditor_User add-on'
do
let
(
:license
)
{
build
(
:license
)
}
before
do
allow
(
::
License
).
to
receive
(
:current
).
and_return
(
license
)
end
context
'creating an auditor user'
do
it
"does not allow creating an auditor user if the addon isn't enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
false
}
expect
(
build
(
:user
,
:auditor
)).
to
be_invalid
end
it
"does not allow creating an auditor user if no license is present"
do
allow
(
License
).
to
receive
(
:current
).
and_return
nil
expect
(
build
(
:user
,
:auditor
)).
to
be_invalid
end
it
"allows creating an auditor user if the addon is enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
true
}
expect
(
build
(
:user
,
:auditor
)).
to
be_valid
end
it
"allows creating a regular user if the addon isn't enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
false
}
expect
(
build
(
:user
)).
to
be_valid
end
end
context
'#auditor?'
do
it
"returns true for an auditor user if the addon is enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
true
}
expect
(
build
(
:user
,
:auditor
)).
to
be_auditor
end
it
"returns false for an auditor user if the addon is not enabled"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
false
}
expect
(
build
(
:user
,
:auditor
)).
not_to
be_auditor
end
it
"returns false for an auditor user if a license is not present"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
false
}
expect
(
build
(
:user
,
:auditor
)).
not_to
be_auditor
end
it
"returns false for a non-auditor user even if the addon is present"
do
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_Auditor_User'
)
{
true
}
expect
(
build
(
:user
)).
not_to
be_auditor
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