Project

General

Profile

RE: Hide public projects for specific roles ยป hide_projects_v1.5.diff

for Redmine 4.1 - Alexander Bohn, 2022-05-23 12:02

View differences:

app/helpers/application_helper.rb
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)))
only_path = options[:only_path].nil? ? true : options[:only_path]
link_to name, user_url(user, :only_path => only_path), :class => user.css_classes
else
app/helpers/projects_helper.rb
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)
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
if User.current.admin?
links << link_to(l(:label_administration), admin_projects_path, :class => 'icon icon-settings')
......
# 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-user 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-user 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
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
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
# Permissions
Redmine::AccessControl.map do |map|
map.permission :view_project, {:projects => [:show, :bookmark], :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
    (1-1/1)