Project

General

Profile

RE: Hide public projects for specific roles ยป hide_projects_1.6_for_redmine5.1.patch

Tim Lee, 2023-12-18 09:27

View differences:

app/helpers/application_helper.rb
name = h(principal.name(options[:format]))
name = "@".html_safe + name if options[:mention]
css_classes = ''
if principal.active? || (User.current.admin? && principal.logged?)
if principal.active? || (User.current.admin? && principal.logged?) && (User.current.admin? && (not User.current.allowed_to?(:hide_public_projects, nil, :global => true)))
url = user_url(principal, :only_path => only_path)
css_classes += principal.css_classes
end
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 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')
......
classes = project.css_classes.split
classes += %w(icon icon-user my-project) if User.current.member_of?(project)
classes += %w(icon icon-bookmarked-project) if bookmarked_project_ids.include?(project.id)
s = link_to_project(project, {}, :class => classes.uniq.join(' '))
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 => classes.uniq.join(' '))
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
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
[]
......
return false unless roles
roles.any? do |role|
(context.is_public? || role.member?) &&
((context.is_public? && !allowed_to?(:hide_public_projects, nil, :global => true)) || role.member?) &&
role.allowed_to?(action) &&
(block ? yield(role, self) : true)
end
lib/redmine/preparation.rb
# Permissions
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)