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
d1bec074
Commit
d1bec074
authored
Apr 06, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix service desk controller permissions
parent
e113fc9f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
+35
-9
app/controllers/projects/service_desk_controller.rb
app/controllers/projects/service_desk_controller.rb
+8
-4
spec/controllers/projects/service_desk_controller_spec.rb
spec/controllers/projects/service_desk_controller_spec.rb
+27
-5
No files found.
app/controllers/projects/service_desk_controller.rb
View file @
d1bec074
class
Projects::ServiceDeskController
<
Projects
::
ApplicationController
before_action
:authorize_admin_
project
!
,
only: :update
before_action
:authorize_
read
_project!
,
only: :show
before_action
:authorize_admin_
instance
!
,
only: :update
before_action
:authorize_
admin
_project!
,
only: :show
def
show
json_response
...
...
@@ -16,10 +16,14 @@ class Projects::ServiceDeskController < Projects::ApplicationController
def
json_response
respond_to
do
|
format
|
attributes
=
service_desk_
attributes
=
{
service_desk_address:
project
.
service_desk_address
,
service_desk_enabled:
project
.
service_desk_enabled
}
format
.
json
{
render
json:
attributes
.
to_json
,
status: :ok
}
format
.
json
{
render
json:
service_desk_attributes
}
end
end
def
authorize_admin_instance!
return
render_404
unless
current_user
.
is_admin?
end
end
spec/controllers/projects/service_desk_controller_spec.rb
View file @
d1bec074
...
...
@@ -2,19 +2,18 @@ require 'spec_helper'
describe
Projects
::
ServiceDeskController
do
let
(
:project
)
{
create
(
:project_empty_repo
,
:private
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
,
admin:
true
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
and_call_original
allow_any_instance_of
(
License
).
to
receive
(
:add_on?
).
with
(
'GitLab_ServiceDesk'
)
{
true
}
project
.
update
(
service_desk_enabled:
true
)
project
.
add_master
(
user
)
sign_in
(
user
)
end
describe
'GET service desk properties'
do
it
'returns service_desk JSON data'
do
project
.
update
(
service_desk_enabled:
true
)
get
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
format: :json
body
=
JSON
.
parse
(
response
.
body
)
...
...
@@ -22,6 +21,19 @@ describe Projects::ServiceDeskController do
expect
(
body
[
"service_desk_enabled"
]).
to
be_truthy
expect
(
response
.
status
).
to
eq
(
200
)
end
context
'when user is not project master'
do
let
(
:guest
)
{
create
(
:user
)
}
it
'renders 404'
do
project
.
add_guest
(
guest
)
sign_in
(
guest
)
get
:show
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
format: :json
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
describe
'PUT service desk properties'
do
...
...
@@ -38,5 +50,15 @@ describe Projects::ServiceDeskController do
expect
(
body
[
"service_desk_enabled"
]).
to
be_truthy
expect
(
response
.
status
).
to
eq
(
200
)
end
context
'when user is not admin'
do
before
{
user
.
update
(
admin:
false
)
}
it
'renders 404'
do
put
:update
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
service_desk_enabled:
true
,
format: :json
expect
(
response
.
status
).
to
eq
(
404
)
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