Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
0189ee97
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,体验更适合开发者的 AI 搜索 >>
提交
0189ee97
编写于
10月 21, 2012
作者:
R
randx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Security for online editor. Replace dev_access?, master_access? with can? method usage
上级
5ec1ad8b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
56 addition
and
18 deletion
+56
-18
app/controllers/tree_controller.rb
app/controllers/tree_controller.rb
+8
-0
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+8
-0
app/models/ability.rb
app/models/ability.rb
+6
-1
app/roles/authority.rb
app/roles/authority.rb
+1
-1
app/roles/repository.rb
app/roles/repository.rb
+5
-0
app/views/tree/_blob_actions.html.haml
app/views/tree/_blob_actions.html.haml
+1
-1
lib/gitlab/backend/grack_auth.rb
lib/gitlab/backend/grack_auth.rb
+27
-15
未找到文件。
app/controllers/tree_controller.rb
浏览文件 @
0189ee97
...
...
@@ -48,5 +48,13 @@ class TreeController < ProjectResourceController
unless
@tree
.
is_blob?
&&
@tree
.
text?
redirect_to
project_tree_path
(
@project
,
@id
),
notice:
"You can only edit text files"
end
allowed
=
if
project
.
protected_branch?
@ref
can?
(
current_user
,
:push_code_to_protected_branches
,
project
)
else
can?
(
current_user
,
:push_code
,
project
)
end
return
access_denied!
unless
allowed
end
end
app/helpers/tree_helper.rb
浏览文件 @
0189ee97
...
...
@@ -59,4 +59,12 @@ module TreeHelper
def
tree_join
(
*
args
)
File
.
join
(
*
args
)
end
def
allowed_tree_edit?
if
@project
.
protected_branch?
@ref
can?
(
current_user
,
:push_code_to_protected_branches
,
@project
)
else
can?
(
current_user
,
:push_code
,
@project
)
end
end
end
app/models/ability.rb
浏览文件 @
0189ee97
...
...
@@ -35,9 +35,14 @@ class Ability
]
if
project
.
report_access_for?
(
user
)
rules
<<
[
:write_wiki
:write_wiki
,
:push_code
]
if
project
.
dev_access_for?
(
user
)
rules
<<
[
:push_code_to_protected_branches
]
if
project
.
master_access_for?
(
user
)
rules
<<
[
:modify_issue
,
:modify_snippet
,
...
...
app/roles/authority.rb
浏览文件 @
0189ee97
...
...
@@ -53,6 +53,6 @@ module Authority
end
def
master_access_for?
(
user
)
!
users_projects
.
where
(
user_id:
user
.
id
,
project_access:
[
UsersProject
::
MASTER
]).
empty?
||
owner_id
==
user
.
id
!
users_projects
.
where
(
user_id:
user
.
id
,
project_access:
[
UsersProject
::
MASTER
]).
empty?
end
end
app/roles/repository.rb
浏览文件 @
0189ee97
...
...
@@ -181,4 +181,9 @@ module Repository
def
http_url_to_repo
http_url
=
[
Gitlab
.
config
.
url
,
"/"
,
path
,
".git"
].
join
(
''
)
end
# Check if current branch name is marked as protected in the system
def
protected_branch?
branch_name
protected_branches
.
map
(
&
:name
).
include?
(
branch_name
)
end
end
app/views/tree/_blob_actions.html.haml
浏览文件 @
0189ee97
.btn-group.tree-btn-group
-# only show edit link for text files
-
if
@tree
.
text?
=
link_to
"edit"
,
edit_project_tree_path
(
@project
,
@id
),
class:
"btn very_small"
=
link_to
"edit"
,
edit_project_tree_path
(
@project
,
@id
),
class:
"btn very_small"
,
disabled:
!
allowed_tree_edit?
=
link_to
"raw"
,
project_blob_path
(
@project
,
@id
),
class:
"btn very_small"
,
target:
"_blank"
-# only show normal/blame view links for text files
-
if
@tree
.
text?
...
...
lib/gitlab/backend/grack_auth.rb
浏览文件 @
0189ee97
module
Grack
class
Auth
<
Rack
::
Auth
::
Basic
attr_accessor
:user
,
:project
def
valid?
# Authentication with username and password
email
,
password
=
@auth
.
credentials
user
=
User
.
find_by_email
(
email
)
self
.
user
=
User
.
find_by_email
(
email
)
return
false
unless
user
.
try
(
:valid_password?
,
password
)
# Set GL_USER env variable
...
...
@@ -18,28 +19,39 @@ module Grack
# Find project by PATH_INFO from env
if
m
=
/^\/([\w-]+).git/
.
match
(
@request
.
path_info
).
to_a
return
false
unless
project
=
Project
.
find_by_path
(
m
.
last
)
self
.
project
=
Project
.
find_by_path
(
m
.
last
)
return
false
unless
project
end
# Git upload and receive
if
@request
.
get?
true
validate_get_request
elsif
@request
.
post?
if
@request
.
path_info
.
end_with?
(
'git-upload-pack'
)
return
project
.
dev_access_for?
(
user
)
elsif
@request
.
path_info
.
end_with?
(
'git-receive-pack'
)
if
project
.
protected_branches
.
map
(
&
:name
).
include?
(
current_ref
)
project
.
master_access_for?
(
user
)
else
project
.
dev_access_for?
(
user
)
end
else
false
end
validate_post_request
else
false
end
end
# valid?
end
def
validate_get_request
true
end
def
validate_post_request
if
@request
.
path_info
.
end_with?
(
'git-upload-pack'
)
can?
(
user
,
:push_code
,
project
)
elsif
@request
.
path_info
.
end_with?
(
'git-receive-pack'
)
action
=
if
project
.
protected_branch?
(
current_ref
)
:push_code_to_protected_branches
else
:push_code
end
can?
(
user
,
action
,
project
)
else
false
end
end
def
current_ref
if
@env
[
"HTTP_CONTENT_ENCODING"
]
=~
/gzip/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录