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
51 51
  def link_to_user(user, options={})
52 52
    if user.is_a?(User)
53 53
      name = h(user.name(options[:format]))
54
      if user.active? || (User.current.admin? && user.logged?)
54
      if user.active? || (User.current.admin? && user.logged?) && (User.current.admin? && (not User.current.allowed_to?(:hide_public_projects, nil, :global => true)))
55 55
        only_path = options[:only_path].nil? ? true : options[:only_path]
56 56
        link_to name, user_url(user, :only_path => only_path), :class => user.css_classes
57 57
      else
app/helpers/projects_helper.rb
62 62

  
63 63
  def render_project_action_links
64 64
    links = (+"").html_safe
65
    if User.current.allowed_to?(:add_project, nil, :global => true)
66
      links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
65
    if not User.current.allowed_to?(:hide_public_projects, nil, :global => true)
66
      if User.current.allowed_to?(:add_project, nil, :global => true)
67
        links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
68
      end
67 69
    end
68 70
    if User.current.admin?
69 71
      links << link_to(l(:label_administration), admin_projects_path, :class => 'icon icon-settings')
......
74 76
  # Renders the projects index
75 77
  def render_project_hierarchy(projects)
76 78
    render_project_nested_lists(projects) do |project|
77
      s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'icon icon-user my-project' : nil}")
78
      if project.description.present?
79
        s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
79
      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))
80
        s = ""
81
      else
82
        s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'icon icon-user my-project' : nil}")
83
        if project.description.present?
84
          s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
85
        end
80 86
      end
81 87
      s
82 88
    end
app/models/project.rb
188 188
      statement_by_role = {}
189 189
      unless options[:member]
190 190
        role = user.builtin_role
191
        if role.allowed_to?(permission)
191
        if role.allowed_to?(permission) && !user.allowed_to?(:hide_public_projects, nil, :global => true)
192 192
          s = "#{Project.table_name}.is_public = #{connection.quoted_true}"
193 193
          if user.id
194 194
            group = role.anonymous? ? Group.anonymous : Group.non_member
app/models/user.rb
603 603
    return [] if project.nil? || project.archived?
604 604
    if membership = membership(project)
605 605
      membership.roles.to_a
606
    elsif project.is_public?
606
    elsif project.is_public? && !allowed_to?(:hide_public_projects, nil, :global => true)
607 607
      project.override_roles(builtin_role)
608 608
    else
609 609
      []
......
705 705
      roles = roles_for_project(context)
706 706
      return false unless roles
707 707
      roles.any? {|role|
708
        (context.is_public? || role.member?) &&
708
        ((context.is_public? && !allowed_to?(:hide_public_projects, nil, :global => true)) || role.member?) &&
709 709
        role.allowed_to?(action) &&
710 710
        (block_given? ? yield(role, self) : true)
711 711
      }
lib/redmine.rb
79 79
# Permissions
80 80
Redmine::AccessControl.map do |map|
81 81
  map.permission :view_project, {:projects => [:show, :bookmark], :activities => [:index]}, :public => true, :read => true
82
  map.permission :hide_public_projects, {:projects => [:show]}, :require => :loggedin
82 83
  map.permission :search_project, {:search => :index}, :public => true, :read => true
83 84
  map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
84 85
  map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
    (1-1/1)