Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
3656d3b8
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3656d3b8
编写于
8月 16, 2016
作者:
H
http://jneen.net/
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add automatic detection of the policy class
上级
16fe6dc7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
16 deletion
+18
-16
app/models/ability.rb
app/models/ability.rb
+3
-15
app/policies/base_policy.rb
app/policies/base_policy.rb
+15
-1
未找到文件。
app/models/ability.rb
浏览文件 @
3656d3b8
...
@@ -61,6 +61,9 @@ class Ability
...
@@ -61,6 +61,9 @@ class Ability
private
private
def
uncached_allowed
(
user
,
subject
)
def
uncached_allowed
(
user
,
subject
)
policy_class
=
BasePolicy
.
class_for
(
subject
)
rescue
nil
return
policy_class
.
abilities
(
user
,
subject
)
if
policy_class
return
anonymous_abilities
(
subject
)
if
user
.
nil?
return
anonymous_abilities
(
subject
)
if
user
.
nil?
return
[]
unless
user
.
is_a?
(
User
)
return
[]
unless
user
.
is_a?
(
User
)
return
[]
if
user
.
blocked?
return
[]
if
user
.
blocked?
...
@@ -70,13 +73,6 @@ class Ability
...
@@ -70,13 +73,6 @@ class Ability
def
abilities_by_subject_class
(
user
:,
subject
:)
def
abilities_by_subject_class
(
user
:,
subject
:)
case
subject
case
subject
when
Project
then
ProjectPolicy
.
abilities
(
user
,
subject
)
when
Issue
then
IssuePolicy
.
abilities
(
user
,
subject
)
when
MergeRequest
then
MergeRequestPolicy
.
abilities
(
user
,
subject
)
when
Ci
::
Build
then
Ci
::
BuildPolicy
.
abilities
(
user
,
subject
)
when
CommitStatus
then
CommitStatus
.
abilities
(
user
,
subject
)
when
Note
then
note_abilities
(
user
,
subject
)
when
ProjectSnippet
then
project_snippet_abilities
(
user
,
subject
)
when
ProjectSnippet
then
project_snippet_abilities
(
user
,
subject
)
when
PersonalSnippet
then
personal_snippet_abilities
(
user
,
subject
)
when
PersonalSnippet
then
personal_snippet_abilities
(
user
,
subject
)
when
Group
then
group_abilities
(
user
,
subject
)
when
Group
then
group_abilities
(
user
,
subject
)
...
@@ -96,14 +92,6 @@ class Ability
...
@@ -96,14 +92,6 @@ class Ability
anonymous_personal_snippet_abilities
(
subject
)
anonymous_personal_snippet_abilities
(
subject
)
elsif
subject
.
is_a?
(
ProjectSnippet
)
elsif
subject
.
is_a?
(
ProjectSnippet
)
anonymous_project_snippet_abilities
(
subject
)
anonymous_project_snippet_abilities
(
subject
)
elsif
subject
.
is_a?
(
CommitStatus
)
anonymous_commit_status_abilities
(
subject
)
elsif
subject
.
is_a?
(
Project
)
ProjectPolicy
.
abilities
(
nil
,
subject
)
elsif
subject
.
is_a?
(
Issue
)
IssuePolicy
.
abilities
(
nil
,
subject
)
elsif
subject
.
is_a?
(
MergeRequest
)
MergeRequestPolicy
.
abilities
(
nil
,
subject
)
elsif
subject
.
respond_to?
(
:project
)
elsif
subject
.
respond_to?
(
:project
)
ProjectPolicy
.
abilities
(
nil
,
subject
.
project
)
ProjectPolicy
.
abilities
(
nil
,
subject
.
project
)
elsif
subject
.
is_a?
(
Group
)
||
subject
.
respond_to?
(
:group
)
elsif
subject
.
is_a?
(
Group
)
||
subject
.
respond_to?
(
:group
)
...
...
app/policies/base_policy.rb
浏览文件 @
3656d3b8
...
@@ -4,7 +4,21 @@ class BasePolicy
...
@@ -4,7 +4,21 @@ class BasePolicy
end
end
def
self
.
class_for
(
subject
)
def
self
.
class_for
(
subject
)
"
#{
subject
.
class
.
name
}
Policy"
.
constantize
subject
.
class
.
ancestors
.
each
do
|
klass
|
next
unless
klass
.
name
begin
policy_class
=
"
#{
klass
.
name
}
Policy"
.
constantize
# NB: the < operator here tests whether policy_class
# inherits from BasePolicy
return
policy_class
if
policy_class
<
BasePolicy
rescue
NameError
nil
end
end
raise
"no policy for
#{
subject
.
class
.
name
}
"
end
end
attr_reader
:user
,
:subject
attr_reader
:user
,
:subject
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录