BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ccc9bed8
Commit
ccc9bed8
authored
Dec 15, 2011
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Abilities refactoring
parent
7a9fc480
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
8 deletions
+83
-8
issues_controller.rb
app/controllers/issues_controller.rb
+20
-1
merge_requests_controller.rb
app/controllers/merge_requests_controller.rb
+21
-2
notes_controller.rb
app/controllers/notes_controller.rb
+2
-0
snippets_controller.rb
app/controllers/snippets_controller.rb
+21
-1
team_members_controller.rb
app/controllers/team_members_controller.rb
+1
-1
ability.rb
app/models/ability.rb
+6
-3
project.rb
app/models/project.rb
+12
-0
No files found.
app/controllers/issues_controller.rb
View file @
ccc9bed8
...
...
@@ -6,8 +6,18 @@ class IssuesController < ApplicationController
# Authorize
before_filter
:add_project_abilities
# Allow read any issue
before_filter
:authorize_read_issue!
before_filter
:authorize_write_issue!
,
:only
=>
[
:new
,
:create
,
:close
,
:edit
,
:update
,
:sort
]
# Allow write(create) issue
before_filter
:authorize_write_issue!
,
:only
=>
[
:new
,
:create
]
# Allow modify issue
before_filter
:authorize_modify_issue!
,
:only
=>
[
:close
,
:edit
,
:update
,
:sort
]
# Allow destroy issue
before_filter
:authorize_admin_issue!
,
:only
=>
[
:destroy
]
respond_to
:js
,
:html
...
...
@@ -115,4 +125,13 @@ class IssuesController < ApplicationController
def
issue
@issue
||=
@project
.
issues
.
find
(
params
[
:id
])
end
def
authorize_modify_issue!
can?
(
current_user
,
:modify_issue
,
@issue
)
||
@issue
.
assignee
==
current_user
end
def
authorize_admin_issue!
can?
(
current_user
,
:admin_issue
,
@issue
)
end
end
app/controllers/merge_requests_controller.rb
View file @
ccc9bed8
...
...
@@ -6,8 +6,18 @@ class MergeRequestsController < ApplicationController
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_write_project!
,
:only
=>
[
:new
,
:create
,
:edit
,
:update
]
# Allow read any merge_request
before_filter
:authorize_read_merge_request!
# Allow write(create) merge_request
before_filter
:authorize_write_merge_request!
,
:only
=>
[
:new
,
:create
]
# Allow modify merge_request
before_filter
:authorize_modify_merge_request!
,
:only
=>
[
:close
,
:edit
,
:update
,
:sort
]
# Allow destroy merge_request
before_filter
:authorize_admin_merge_request!
,
:only
=>
[
:destroy
]
def
index
@merge_requests
=
@project
.
merge_requests
...
...
@@ -85,4 +95,13 @@ class MergeRequestsController < ApplicationController
def
merge_request
@merge_request
||=
@project
.
merge_requests
.
find
(
params
[
:id
])
end
def
authorize_modify_merge_request!
can?
(
current_user
,
:modify_merge_request
,
@merge_request
)
||
@merge_request
.
assignee
==
current_user
end
def
authorize_admin_merge_request!
can?
(
current_user
,
:admin_merge_request
,
@merge_request
)
end
end
app/controllers/notes_controller.rb
View file @
ccc9bed8
...
...
@@ -3,6 +3,8 @@ class NotesController < ApplicationController
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_note!
before_filter
:authorize_write_note!
,
:only
=>
[
:create
]
respond_to
:js
...
...
app/controllers/snippets_controller.rb
View file @
ccc9bed8
...
...
@@ -5,8 +5,18 @@ class SnippetsController < ApplicationController
# Authorize
before_filter
:add_project_abilities
# Allow read any snippet
before_filter
:authorize_read_snippet!
before_filter
:authorize_write_snippet!
,
:only
=>
[
:new
,
:create
,
:close
,
:edit
,
:update
,
:sort
]
# Allow write(create) snippet
before_filter
:authorize_write_snippet!
,
:only
=>
[
:new
,
:create
]
# Allow modify snippet
before_filter
:authorize_modify_snippet!
,
:only
=>
[
:edit
,
:update
]
# Allow destroy snippet
before_filter
:authorize_admin_snippet!
,
:only
=>
[
:destroy
]
respond_to
:html
...
...
@@ -60,4 +70,14 @@ class SnippetsController < ApplicationController
redirect_to
project_snippets_path
(
@project
)
end
protected
def
authorize_modify_snippet!
can?
(
current_user
,
:modify_snippet
,
@snippet
)
end
def
authorize_admin_snippet!
can?
(
current_user
,
:admin_snippet
,
@snippet
)
end
end
app/controllers/team_members_controller.rb
View file @
ccc9bed8
...
...
@@ -5,7 +5,7 @@ class TeamMembersController < ApplicationController
# Authorize
before_filter
:add_project_abilities
before_filter
:authorize_read_project!
before_filter
:authorize_admin_project!
,
:
only
=>
[
:new
,
:create
,
:destroy
,
:update
]
before_filter
:authorize_admin_project!
,
:
except
=>
[
:show
]
def
show
@team_member
=
project
.
users_projects
.
find
(
params
[
:id
])
...
...
app/models/ability.rb
View file @
ccc9bed8
...
...
@@ -19,7 +19,7 @@ class Ability
:read_team_member
,
:read_merge_request
,
:read_note
]
if
project
.
readers
.
include
?
(
user
)
]
if
project
.
allow_read_for
?
(
user
)
rules
<<
[
:write_project
,
...
...
@@ -27,16 +27,18 @@ class Ability
:write_snippet
,
:write_merge_request
,
:write_note
]
if
project
.
writers
.
include
?
(
user
)
]
if
project
.
allow_write_for
?
(
user
)
rules
<<
[
:modify_issue
,
:modify_snippet
,
:admin_project
,
:admin_issue
,
:admin_snippet
,
:admin_team_member
,
:admin_merge_request
,
:admin_note
]
if
project
.
a
dmins
.
include
?
(
user
)
]
if
project
.
a
llow_admin_for
?
(
user
)
rules
.
flatten
end
...
...
@@ -48,6 +50,7 @@ class Ability
[
:"read_
#{
name
}
"
,
:"write_
#{
name
}
"
,
:"modify_
#{
name
}
"
,
:"admin_
#{
name
}
"
]
else
...
...
app/models/project.rb
View file @
ccc9bed8
...
...
@@ -161,6 +161,18 @@ class Project < ActiveRecord::Base
@admins
||=
users_projects
.
includes
(
:user
).
where
(
:project_access
=>
PROJECT_RWA
).
map
(
&
:user
)
end
def
allow_read_for?
(
user
)
!
users_projects
.
where
(
:user_id
=>
user
.
id
,
:project_access
=>
[
PROJECT_R
,
PROJECT_RW
,
PROJECT_RWA
]).
empty?
end
def
allow_write_for?
(
user
)
!
users_projects
.
where
(
:user_id
=>
user
.
id
,
:project_access
=>
[
PROJECT_RW
,
PROJECT_RWA
]).
empty?
end
def
allow_admin_for?
(
user
)
!
users_projects
.
where
(
:user_id
=>
user
.
id
,
:project_access
=>
[
PROJECT_RWA
]).
empty?
||
owner_id
==
user
.
id
end
def
root_ref
default_branch
||
"master"
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