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
62 62
      name = h(principal.name(options[:format]))
63 63
      name = "@".html_safe + name if options[:mention]
64 64
      css_classes = ''
65
      if principal.active? || (User.current.admin? && principal.logged?)
65
      if principal.active? || (User.current.admin? && principal.logged?) && (User.current.admin? && (not User.current.allowed_to?(:hide_public_projects, nil, :global => true)))
66 66
        url = user_url(principal, :only_path => only_path)
67 67
        css_classes += principal.css_classes
68 68
      end
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 User.current.allowed_to?(:add_project, nil, :global => true)
66
    #  links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
67
    if not User.current.allowed_to(:hide_public_projects, nil, :global=>true)
68
      if User.current.allowed_to?(:add_project, nil, :global => true)
69
        links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
70
      end
67 71
    end
68 72
    if User.current.admin?
69 73
      links << link_to(l(:label_administration), admin_projects_path, :class => 'icon icon-settings')
......
78 82
      classes = project.css_classes.split
79 83
      classes += %w(icon icon-user my-project) if User.current.member_of?(project)
80 84
      classes += %w(icon icon-bookmarked-project) if bookmarked_project_ids.include?(project.id)
81
      s = link_to_project(project, {}, :class => classes.uniq.join(' '))
82
      if project.description.present?
83
        s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
85
      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))
86
        s = ""
87
      else
88
        s = link_to_project(project, {}, :class => classes.uniq.join(' '))
89
        if project.description.present?
90
          s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
91
        end
84 92
      end
85 93
      s
86 94
    end
app/models/project.rb
205 205
      statement_by_role = {}
206 206
      unless options[:member]
207 207
        role = user.builtin_role
208
        if role.allowed_to?(permission)
208
        if role.allowed_to?(permission) && !user.allowed_to?(:hide_public_projects, nil, :global => true)
209 209
          s = "#{Project.table_name}.is_public = #{connection.quoted_true}"
210 210
          if user.id
211 211
            group = role.anonymous? ? Group.anonymous : Group.non_member
app/models/user.rb
645 645

  
646 646
    if membership = membership(project)
647 647
      membership.roles.to_a
648
    elsif project.is_public?
648
    elsif project.is_public? && !allowed_to?(:hide_public_projects, nil, :global => true)
649 649
      project.override_roles(builtin_role)
650 650
    else
651 651
      []
......
748 748
      return false unless roles
749 749

  
750 750
      roles.any? do |role|
751
        (context.is_public? || role.member?) &&
751
        ((context.is_public? && !allowed_to?(:hide_public_projects, nil, :global => true)) || role.member?) &&
752 752
        role.allowed_to?(action) &&
753 753
        (block ? yield(role, self) : true)
754 754
      end
lib/redmine/preparation.rb
34 34
      # Permissions
35 35
      AccessControl.map do |map|
36 36
        map.permission :view_project, {:projects => [:show, :bookmark], :activities => [:index]}, :public => true, :read => true
37
        map.permission :hide_public_projects, {:projects => [:show]}, :require => :loggedin
37 38
        map.permission :search_project, {:search => :index}, :public => true, :read => true
38 39
        map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
39 40
        map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
    (1-1/1)