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
76bd0932
Commit
76bd0932
authored
Nov 14, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use declared_params helper in API
parent
36fa5d66
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
20 additions
and
36 deletions
+20
-36
lib/api/access_requests.rb
lib/api/access_requests.rb
+1
-1
lib/api/broadcast_messages.rb
lib/api/broadcast_messages.rb
+2
-4
lib/api/commits.rb
lib/api/commits.rb
+1
-1
lib/api/deploy_keys.rb
lib/api/deploy_keys.rb
+1
-1
lib/api/environments.rb
lib/api/environments.rb
+3
-4
lib/api/labels.rb
lib/api/labels.rb
+3
-8
lib/api/members.rb
lib/api/members.rb
+1
-1
lib/api/notification_settings.rb
lib/api/notification_settings.rb
+2
-5
lib/api/project_hooks.rb
lib/api/project_hooks.rb
+3
-7
lib/api/system_hooks.rb
lib/api/system_hooks.rb
+1
-1
lib/api/tags.rb
lib/api/tags.rb
+1
-2
lib/api/users.rb
lib/api/users.rb
+1
-1
No files found.
lib/api/access_requests.rb
View file @
76bd0932
...
@@ -48,7 +48,7 @@ module API
...
@@ -48,7 +48,7 @@ module API
put
':id/access_requests/:user_id/approve'
do
put
':id/access_requests/:user_id/approve'
do
source
=
find_source
(
source_type
,
params
[
:id
])
source
=
find_source
(
source_type
,
params
[
:id
])
member
=
::
Members
::
ApproveAccessRequestService
.
new
(
source
,
current_user
,
declared
(
params
)
).
execute
member
=
::
Members
::
ApproveAccessRequestService
.
new
(
source
,
current_user
,
declared
_params
).
execute
status
:created
status
:created
present
member
.
user
,
with:
Entities
::
Member
,
member:
member
present
member
.
user
,
with:
Entities
::
Member
,
member:
member
...
...
lib/api/broadcast_messages.rb
View file @
76bd0932
...
@@ -36,8 +36,7 @@ module API
...
@@ -36,8 +36,7 @@ module API
optional
:font
,
type:
String
,
desc:
'Foreground color'
optional
:font
,
type:
String
,
desc:
'Foreground color'
end
end
post
do
post
do
create_params
=
declared
(
params
,
include_missing:
false
).
to_h
message
=
BroadcastMessage
.
create
(
declared_params
(
include_missing:
false
))
message
=
BroadcastMessage
.
create
(
create_params
)
if
message
.
persisted?
if
message
.
persisted?
present
message
,
with:
Entities
::
BroadcastMessage
present
message
,
with:
Entities
::
BroadcastMessage
...
@@ -73,9 +72,8 @@ module API
...
@@ -73,9 +72,8 @@ module API
end
end
put
':id'
do
put
':id'
do
message
=
find_message
message
=
find_message
update_params
=
declared
(
params
,
include_missing:
false
).
to_h
if
message
.
update
(
update_params
)
if
message
.
update
(
declared_params
(
include_missing:
false
)
)
present
message
,
with:
Entities
::
BroadcastMessage
present
message
,
with:
Entities
::
BroadcastMessage
else
else
render_validation_error!
(
message
)
render_validation_error!
(
message
)
...
...
lib/api/commits.rb
View file @
76bd0932
...
@@ -53,7 +53,7 @@ module API
...
@@ -53,7 +53,7 @@ module API
post
":id/repository/commits"
do
post
":id/repository/commits"
do
authorize!
:push_code
,
user_project
authorize!
:push_code
,
user_project
attrs
=
declared
(
params
)
attrs
=
declared
_params
attrs
[
:source_branch
]
=
attrs
[
:branch_name
]
attrs
[
:source_branch
]
=
attrs
[
:branch_name
]
attrs
[
:target_branch
]
=
attrs
[
:branch_name
]
attrs
[
:target_branch
]
=
attrs
[
:branch_name
]
attrs
[
:actions
].
map!
do
|
action
|
attrs
[
:actions
].
map!
do
|
action
|
...
...
lib/api/deploy_keys.rb
View file @
76bd0932
...
@@ -82,7 +82,7 @@ module API
...
@@ -82,7 +82,7 @@ module API
end
end
post
":id/
#{
path
}
/:key_id/enable"
do
post
":id/
#{
path
}
/:key_id/enable"
do
key
=
::
Projects
::
EnableDeployKeyService
.
new
(
user_project
,
key
=
::
Projects
::
EnableDeployKeyService
.
new
(
user_project
,
current_user
,
declared
(
params
)
).
execute
current_user
,
declared
_params
).
execute
if
key
if
key
present
key
,
with:
Entities
::
SSHKey
present
key
,
with:
Entities
::
SSHKey
...
...
lib/api/environments.rb
View file @
76bd0932
...
@@ -32,8 +32,7 @@ module API
...
@@ -32,8 +32,7 @@ module API
post
':id/environments'
do
post
':id/environments'
do
authorize!
:create_environment
,
user_project
authorize!
:create_environment
,
user_project
create_params
=
declared
(
params
,
include_parent_namespaces:
false
).
to_h
environment
=
user_project
.
environments
.
create
(
declared_params
)
environment
=
user_project
.
environments
.
create
(
create_params
)
if
environment
.
persisted?
if
environment
.
persisted?
present
environment
,
with:
Entities
::
Environment
present
environment
,
with:
Entities
::
Environment
...
@@ -55,8 +54,8 @@ module API
...
@@ -55,8 +54,8 @@ module API
authorize!
:update_environment
,
user_project
authorize!
:update_environment
,
user_project
environment
=
user_project
.
environments
.
find
(
params
[
:environment_id
])
environment
=
user_project
.
environments
.
find
(
params
[
:environment_id
])
update_params
=
declared
(
params
,
include_missing:
false
).
extract!
(
:name
,
:external_url
).
to_h
update_params
=
declared
_params
(
include_missing:
false
).
extract!
(
:name
,
:external_url
)
if
environment
.
update
(
update_params
)
if
environment
.
update
(
update_params
)
present
environment
,
with:
Entities
::
Environment
present
environment
,
with:
Entities
::
Environment
else
else
...
...
lib/api/labels.rb
View file @
76bd0932
...
@@ -30,10 +30,7 @@ module API
...
@@ -30,10 +30,7 @@ module API
conflict!
(
'Label already exists'
)
if
label
conflict!
(
'Label already exists'
)
if
label
priority
=
params
.
delete
(
:priority
)
priority
=
params
.
delete
(
:priority
)
label_params
=
declared
(
params
,
label
=
user_project
.
labels
.
create
(
declared_params
(
include_missing:
false
))
include_parent_namespaces:
false
,
include_missing:
false
).
to_h
label
=
user_project
.
labels
.
create
(
label_params
)
if
label
.
valid?
if
label
.
valid?
label
.
prioritize!
(
user_project
,
priority
)
if
priority
label
.
prioritize!
(
user_project
,
priority
)
if
priority
...
@@ -77,11 +74,9 @@ module API
...
@@ -77,11 +74,9 @@ module API
update_priority
=
params
.
key?
(
:priority
)
update_priority
=
params
.
key?
(
:priority
)
priority
=
params
.
delete
(
:priority
)
priority
=
params
.
delete
(
:priority
)
label_params
=
declared
(
params
,
label_params
=
declared_params
(
include_missing:
false
)
include_parent_namespaces:
false
,
include_missing:
false
).
to_h
# Rename new name to the actual label attribute name
# Rename new name to the actual label attribute name
label_params
[
:name
]
=
label_params
.
delete
(
'new_name'
)
if
label_params
.
key?
(
'new_name'
)
label_params
[
:name
]
=
label_params
.
delete
(
:new_name
)
if
label_params
.
key?
(
:new_name
)
render_validation_error!
(
label
)
unless
label
.
update
(
label_params
)
render_validation_error!
(
label
)
unless
label
.
update
(
label_params
)
...
...
lib/api/members.rb
View file @
76bd0932
...
@@ -120,7 +120,7 @@ module API
...
@@ -120,7 +120,7 @@ module API
if
member
.
nil?
if
member
.
nil?
{
message:
"Access revoked"
,
id:
params
[
:user_id
].
to_i
}
{
message:
"Access revoked"
,
id:
params
[
:user_id
].
to_i
}
else
else
::
Members
::
DestroyService
.
new
(
source
,
current_user
,
declared
(
params
)
).
execute
::
Members
::
DestroyService
.
new
(
source
,
current_user
,
declared
_params
).
execute
present
member
.
user
,
with:
Entities
::
Member
,
member:
member
present
member
.
user
,
with:
Entities
::
Member
,
member:
member
end
end
...
...
lib/api/notification_settings.rb
View file @
76bd0932
...
@@ -33,10 +33,9 @@ module API
...
@@ -33,10 +33,9 @@ module API
begin
begin
notification_setting
.
transaction
do
notification_setting
.
transaction
do
new_notification_email
=
params
.
delete
(
:notification_email
)
new_notification_email
=
params
.
delete
(
:notification_email
)
declared_params
=
declared
(
params
,
include_missing:
false
).
to_h
current_user
.
update
(
notification_email:
new_notification_email
)
if
new_notification_email
current_user
.
update
(
notification_email:
new_notification_email
)
if
new_notification_email
notification_setting
.
update
(
declared_params
)
notification_setting
.
update
(
declared_params
(
include_missing:
false
)
)
end
end
rescue
ArgumentError
=>
e
# catch level enum error
rescue
ArgumentError
=>
e
# catch level enum error
render_api_error!
e
.
to_s
,
400
render_api_error!
e
.
to_s
,
400
...
@@ -81,9 +80,7 @@ module API
...
@@ -81,9 +80,7 @@ module API
notification_setting
=
current_user
.
notification_settings_for
(
source
)
notification_setting
=
current_user
.
notification_settings_for
(
source
)
begin
begin
declared_params
=
declared
(
params
,
include_missing:
false
).
to_h
notification_setting
.
update
(
declared_params
(
include_missing:
false
))
notification_setting
.
update
(
declared_params
)
rescue
ArgumentError
=>
e
# catch level enum error
rescue
ArgumentError
=>
e
# catch level enum error
render_api_error!
e
.
to_s
,
400
render_api_error!
e
.
to_s
,
400
end
end
...
...
lib/api/project_hooks.rb
View file @
76bd0932
...
@@ -51,8 +51,7 @@ module API
...
@@ -51,8 +51,7 @@ module API
use
:project_hook_properties
use
:project_hook_properties
end
end
post
":id/hooks"
do
post
":id/hooks"
do
new_hook_params
=
declared
(
params
,
include_missing:
false
,
include_parent_namespaces:
false
).
to_h
hook
=
user_project
.
hooks
.
new
(
declared_params
(
include_missing:
false
))
hook
=
user_project
.
hooks
.
new
(
new_hook_params
)
if
hook
.
save
if
hook
.
save
present
hook
,
with:
Entities
::
ProjectHook
present
hook
,
with:
Entities
::
ProjectHook
...
@@ -71,12 +70,9 @@ module API
...
@@ -71,12 +70,9 @@ module API
use
:project_hook_properties
use
:project_hook_properties
end
end
put
":id/hooks/:hook_id"
do
put
":id/hooks/:hook_id"
do
hook
=
user_project
.
hooks
.
find
(
params
[
:hook_id
])
hook
=
user_project
.
hooks
.
find
(
params
.
delete
(
:hook_id
))
new_params
=
declared
(
params
,
include_missing:
false
,
include_parent_namespaces:
false
).
to_h
new_params
.
delete
(
'hook_id'
)
if
hook
.
update_attributes
(
new_params
)
if
hook
.
update_attributes
(
declared_params
(
include_missing:
false
)
)
present
hook
,
with:
Entities
::
ProjectHook
present
hook
,
with:
Entities
::
ProjectHook
else
else
error!
(
"Invalid url given"
,
422
)
if
hook
.
errors
[
:url
].
present?
error!
(
"Invalid url given"
,
422
)
if
hook
.
errors
[
:url
].
present?
...
...
lib/api/system_hooks.rb
View file @
76bd0932
...
@@ -27,7 +27,7 @@ module API
...
@@ -27,7 +27,7 @@ module API
optional
:enable_ssl_verification
,
type:
Boolean
,
desc:
"Do SSL verification when triggering the hook"
optional
:enable_ssl_verification
,
type:
Boolean
,
desc:
"Do SSL verification when triggering the hook"
end
end
post
do
post
do
hook
=
SystemHook
.
new
declared
(
params
,
include_missing:
false
).
to_h
hook
=
SystemHook
.
new
(
declared_params
(
include_missing:
false
))
if
hook
.
save
if
hook
.
save
present
hook
,
with:
Entities
::
Hook
present
hook
,
with:
Entities
::
Hook
...
...
lib/api/tags.rb
View file @
76bd0932
...
@@ -40,10 +40,9 @@ module API
...
@@ -40,10 +40,9 @@ module API
end
end
post
':id/repository/tags'
do
post
':id/repository/tags'
do
authorize_push_project
authorize_push_project
create_params
=
declared
(
params
)
result
=
CreateTagService
.
new
(
user_project
,
current_user
).
result
=
CreateTagService
.
new
(
user_project
,
current_user
).
execute
(
create_params
[
:tag_name
],
create_params
[
:ref
],
create_params
[
:message
],
create_
params
[
:release_description
])
execute
(
params
[
:tag_name
],
params
[
:ref
],
params
[
:message
],
params
[
:release_description
])
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
present
result
[
:tag
],
present
result
[
:tag
],
...
...
lib/api/users.rb
View file @
76bd0932
...
@@ -335,7 +335,7 @@ module API
...
@@ -335,7 +335,7 @@ module API
requires
:id
,
type:
String
,
desc:
'The user ID'
requires
:id
,
type:
String
,
desc:
'The user ID'
end
end
get
':id/events'
do
get
':id/events'
do
user
=
User
.
find_by
(
id:
declared
(
params
).
id
)
user
=
User
.
find_by
(
id:
params
[
:id
]
)
not_found!
(
'User'
)
unless
user
not_found!
(
'User'
)
unless
user
events
=
user
.
events
.
events
=
user
.
events
.
...
...
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