RE: Hide public projects for specific roles ยป hide_projects_v1.4.diff
| app/helpers/application_helper.rb (copie de travail) | ||
|---|---|---|
|
def link_to_user(user, options={})
|
||
|
if user.is_a?(User)
|
||
|
name = h(user.name(options[:format]))
|
||
|
if user.active? || (User.current.admin? && user.logged?)
|
||
|
if (user.active? || (User.current.admin? && user.logged?)) && (User.current.admin? && (not User.current.allowed_to?(:hide_public_projects, nil, :global => true)))
|
||
|
link_to name, user_path(user), :class => user.css_classes
|
||
|
else
|
||
|
name
|
||
| app/helpers/projects_helper.rb (copie de travail) | ||
|---|---|---|
|
def render_project_action_links
|
||
|
links = "".html_safe
|
||
|
if User.current.allowed_to?(:add_project, nil, :global => true)
|
||
|
links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
|
||
|
if (not User.current.allowed_to?(:hide_public_projects, nil, :global => true) or User.current.admin?)
|
||
|
if User.current.allowed_to?(:add_project, nil, :global => true)
|
||
|
links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
|
||
|
end
|
||
|
end
|
||
|
links
|
||
|
end
|
||
| ... | ... | |
|
# Renders the projects index
|
||
|
def render_project_hierarchy(projects)
|
||
|
render_project_nested_lists(projects) do |project|
|
||
|
s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'icon icon-fav my-project' : nil}")
|
||
|
if project.description.present?
|
||
|
s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
|
||
|
if (not User.current.logged?) || ((not User.current.admin) && (not User.current.member_of?(project)) && User.current.allowed_to?(:hide_public_projects, nil, :global => true))
|
||
|
s = ""
|
||
|
else
|
||
|
s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'icon icon-fav my-project' : nil}")
|
||
|
if project.description.present?
|
||
|
s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
|
||
|
end
|
||
|
end
|
||
|
s
|
||
|
end
|
||
| app/models/project.rb (copie de travail) | ||
|---|---|---|
|
statement_by_role = {}
|
||
|
unless options[:member]
|
||
|
role = user.builtin_role
|
||
|
if role.allowed_to?(permission)
|
||
|
if role.allowed_to?(permission) && !user.allowed_to?(:hide_public_projects, nil, :global => true)
|
||
|
s = "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
||
|
if user.id
|
||
|
group = role.anonymous? ? Group.anonymous : Group.non_member
|
||
| app/models/user.rb (copie de travail) | ||
|---|---|---|
|
return [] if project.nil? || project.archived?
|
||
|
if membership = membership(project)
|
||
|
membership.roles.to_a
|
||
|
elsif project.is_public?
|
||
|
elsif project.is_public? && !allowed_to?(:hide_public_projects, nil, :global => true)
|
||
|
project.override_roles(builtin_role)
|
||
|
else
|
||
|
[]
|
||
| ... | ... | |
|
roles = roles_for_project(context)
|
||
|
return false unless roles
|
||
|
roles.any? {|role|
|
||
|
(context.is_public? || role.member?) &&
|
||
|
((context.is_public? && !allowed_to?(:hide_public_projects, nil, :global => true)) || role.member?) &&
|
||
|
role.allowed_to?(action) &&
|
||
|
(block_given? ? yield(role, self) : true)
|
||
|
}
|
||
| lib/redmine.rb (copie de travail) | ||
|---|---|---|
|
# Permissions
|
||
|
Redmine::AccessControl.map do |map|
|
||
|
map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true, :read => true
|
||
|
map.permission :hide_public_projects, {:projects => [:show]}, :require => :loggedin
|
||
|
map.permission :search_project, {:search => :index}, :public => true, :read => true
|
||
|
map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
|
||
|
map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
|
||