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
e90aebe2
Commit
e90aebe2
authored
Mar 25, 2013
by
Andrew8xx8
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Personal snippets controlelr refactored
parent
9bd1983e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
31 deletions
+33
-31
app/controllers/snippets_controller.rb
app/controllers/snippets_controller.rb
+31
-28
app/models/ability.rb
app/models/ability.rb
+2
-3
No files found.
app/controllers/snippets_controller.rb
View file @
e90aebe2
class
SnippetsController
<
ProjectResourceController
before_filter
:module_enabled
class
SnippetsController
<
ApplicationController
before_filter
:snippet
,
only:
[
:show
,
:edit
,
:destroy
,
:update
,
:raw
]
# Allow read any snippet
before_filter
:authorize_read_snippet!
# Allow write(create) snippet
before_filter
:authorize_write_snippet!
,
only:
[
:new
,
:create
]
# Allow modify snippet
before_filter
:authorize_modify_snippet!
,
only:
[
:edit
,
:update
]
...
...
@@ -17,22 +10,39 @@ class SnippetsController < ProjectResourceController
respond_to
:html
def
index
@snippets
=
@project
.
snippets
.
fresh
.
non_expired
@snippets
=
Snippet
.
public
.
fresh
.
non_expired
.
page
(
params
[
:page
]).
per
(
20
)
end
def
user_index
@user
=
User
.
find_by_username
(
params
[
:username
])
@snippets
=
@current_user
.
snippets
.
fresh
.
non_expired
@snippets
=
case
params
[
:scope
]
when
'public'
then
@snippets
.
public
when
'private'
then
@snippets
.
private
else
@snippets
end
@snippets
=
@snippets
.
page
(
params
[
:page
]).
per
(
20
)
end
def
new
@snippet
=
@project
.
snippets
.
new
@snippet
=
PersonalSnippet
.
new
end
def
create
@snippet
=
@project
.
snippets
.
new
(
params
[
:
snippet
])
@snippet
=
PersonalSnippet
.
new
(
params
[
:personal_
snippet
])
@snippet
.
author
=
current_user
@snippet
.
save
if
@snippet
.
valid?
redirect_to
[
@project
,
@snippet
]
redirect_to
snippet_path
(
@snippet
)
else
respond_with
(
@snippet
)
respond_with
@snippet
end
end
...
...
@@ -40,27 +50,24 @@ class SnippetsController < ProjectResourceController
end
def
update
@snippet
.
update_attributes
(
params
[
:snippet
])
@snippet
.
update_attributes
(
params
[
:
personal_
snippet
])
if
@snippet
.
valid?
redirect_to
[
@project
,
@snippet
]
redirect_to
snippet_path
(
@snippet
)
else
respond_with
(
@snippet
)
respond_with
@snippet
end
end
def
show
@note
=
@project
.
notes
.
new
(
noteable:
@snippet
)
@target_type
=
:snippet
@target_id
=
@snippet
.
id
end
def
destroy
return
access_denied!
unless
can?
(
current_user
,
:admin_snippet
,
@snippet
)
return
access_denied!
unless
can?
(
current_user
,
:admin_
personal_
snippet
,
@snippet
)
@snippet
.
destroy
redirect_to
project_snippet_path
(
@project
)
redirect_to
snippets_path
end
def
raw
...
...
@@ -75,18 +82,14 @@ class SnippetsController < ProjectResourceController
protected
def
snippet
@snippet
||=
@project
.
snippets
.
find
(
params
[
:id
])
@snippet
||=
PersonalSnippet
.
find
(
params
[
:id
])
end
def
authorize_modify_snippet!
return
render_404
unless
can?
(
current_user
,
:modify_snippet
,
@snippet
)
return
render_404
unless
can?
(
current_user
,
:modify_
personal_
snippet
,
@snippet
)
end
def
authorize_admin_snippet!
return
render_404
unless
can?
(
current_user
,
:admin_snippet
,
@snippet
)
end
def
module_enabled
return
render_404
unless
@project
.
snippets_enabled
return
render_404
unless
can?
(
current_user
,
:admin_personal_snippet
,
@snippet
)
end
end
app/models/ability.rb
View file @
e90aebe2
...
...
@@ -8,7 +8,7 @@ class Ability
when
"Issue"
then
issue_abilities
(
user
,
subject
)
when
"Note"
then
note_abilities
(
user
,
subject
)
when
"ProjectSnippet"
then
project_snippet_abilities
(
user
,
subject
)
when
"
Snippet"
then
snippet_abilities
(
user
,
subject
)
when
"
PersonalSnippet"
then
personal_
snippet_abilities
(
user
,
subject
)
when
"MergeRequest"
then
merge_request_abilities
(
user
,
subject
)
when
"Group"
,
"Namespace"
then
group_abilities
(
user
,
subject
)
when
"UserTeam"
then
user_team_abilities
(
user
,
subject
)
...
...
@@ -135,8 +135,7 @@ class Ability
rules
.
flatten
end
[
:issue
,
:note
,
:project_snippet
,
:snippet
,
:merge_request
].
each
do
|
name
|
[
:issue
,
:note
,
:project_snippet
,
:personal_snippet
,
:merge_request
].
each
do
|
name
|
define_method
"
#{
name
}
_abilities"
do
|
user
,
subject
|
if
subject
.
author
==
user
[
...
...
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