diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c6fce6e..3f4bace 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -62,7 +62,7 @@ module ApplicationHelper 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 diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index d4f7339..3d09c09 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -62,8 +62,12 @@ module ProjectsHelper 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') @@ -78,9 +82,13 @@ module ProjectsHelper 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 diff --git a/app/models/project.rb b/app/models/project.rb index 11f4a95..c5a45cc 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -205,7 +205,7 @@ class Project < ActiveRecord::Base 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 diff --git a/app/models/user.rb b/app/models/user.rb index cd923e4..ff5db27 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -645,7 +645,7 @@ class User < Principal 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 [] @@ -748,7 +748,7 @@ class User < Principal 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 diff --git a/lib/redmine/preparation.rb b/lib/redmine/preparation.rb index c51ecfd..8215123 100644 --- a/lib/redmine/preparation.rb +++ b/lib/redmine/preparation.rb @@ -34,6 +34,7 @@ module Redmine # 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