版本库权限封装

添加admin可以管理资源的公开私有
This commit is contained in:
huang 2015-05-18 17:02:02 +08:00
parent 3c810a0cee
commit df48d89881
2 changed files with 25 additions and 19 deletions

View File

@ -593,22 +593,37 @@ module ApplicationHelper
Project.project_tree(projects, &block)
end
# 项目版本库可见权限判断
# 条件1、modules中设置不可见或项目没有版本库2、如果项目是私有或者项目版本库隐藏则必须是项目成员才可见
def visible_repository?(project)
@result = false
unless project.enabled_modules.where("name = 'repository'").empty? || project.repositories.count == 0
if (project.hidden_repo || !project.is_public?)
if User.current.member_of?(project)
@result = true
end
else
@result = true
end
end
return @result
end
# 判断当前用户是否为项目管理员
def is_project_manager?(user_id, project_id)
@result = false
mem = Member.where("user_id = ? and project_id = ?",user_id, project_id)
unless mem.blank?
mem.first.roles.to_s.include?("Manager")
@result = true
@result = mem.first.roles.to_s.include?("Manager") ? true : false
end
return @result
end
# 私有项目资源不能引用,不能设置公开私有
# 公开项目资源可以应用,管理员和资源上传者拥有设置公开私有权限
# 公开项目资源可以引用admin和管理员和资源上传者拥有设置公开私有权限
def authority_pubilic_for_files(project, file)
@result = false
if (is_project_manager?(User.current.id, @project.id) || file.author_id == User.current.id) && project_contains_attachment?(project,file) && file.container_id == project.id && file.container_type == "Project"
if (is_project_manager?(User.current.id, @project.id) || file.author_id == User.current.id || User.current.admin) &&
project_contains_attachment?(project,file) && file.container_id == project.id && file.container_type == "Project"
@result = true
end
return @result

View File

@ -39,20 +39,11 @@
</div>
<% end %>
<%# --版本库被设置成私有、module中设置不显示、没有创建版本库 三种情况不显示-- %>
<% unless @project.enabled_modules.where("name = 'repository'").empty? || @project.repositories.count == 0 %>
<% if @project.hidden_repo || !@project.is_public? %>
<% if User.current.member_of?(@project) %>
<div class="subNav">
<%= link_to l(:project_module_repository), {:controller => 'repositories', :action => 'show', :id => @project.id}, :class => "f14 c_blue02" %>
<a class="subnav_num">(<%= @project.repositories.count %>)</a>
</div>
<% end %>
<% else %>
<div class="subNav">
<%= link_to l(:project_module_repository), {:controller => 'repositories', :action => 'show', :id => @project.id}, :class => "f14 c_blue02" %>
<a class="subnav_num">(<%= @project.repositories.count %>)</a>
</div>
<% end %>
<% if visible_repository?(@project) %>
<div class="subNav">
<%= link_to l(:project_module_repository), {:controller => 'repositories', :action => 'show', :id => @project.id}, :class => "f14 c_blue02" %>
<a class="subnav_num">(<%= @project.repositories.count %>)</a>
</div>
<% end %>
<!-- more -->
<div class="subNav subNav_jiantou" id="expand_tools_expand" nhtype="toggle4cookie" data-id="expand_tool_more" data-target="#navContent" data-val="retract"><%= l(:label_project_more) %></div>