private_role_redmine_4.2.patch

Wim DePreter, 2021-04-30 14:19

Download (5.17 KB)

View differences:

app/controllers/reports_controller.rb (working copy)
27 27
    @versions = @project.shared_versions.sorted
28 28
    @priorities = IssuePriority.all.reverse
29 29
    @categories = @project.issue_categories
30
    @assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users).sorted
31
    @authors = @project.users.sorted
30
## begin patch private role
31
    #@assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users).sorted
32
    @assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users.visible).sorted
33
    #@authors = @project.users.sorted
34
    @authors = @project.users.visible.sorted
35
## end patch private role
32 36
    @subprojects = @project.descendants.visible
33 37
    @issues_by_tracker = Issue.by_tracker(@project, with_subprojects)
34 38
    @issues_by_version = Issue.by_version(@project, with_subprojects)
......
66 70
      @report_title = l(:field_category)
67 71
    when "assigned_to"
68 72
      @field = "assigned_to_id"
69
      @rows = (Setting.issue_group_assignment? ? @project.principals : @project.users).sorted
73
## begin patch private role
74
      #@rows = (Setting.issue_group_assignment? ? @project.principals : @project.users).sorted
75
      @rows = (Setting.issue_group_assignment? ? @project.principals : @project.users).visible.sorted
76
## end patch private role
70 77
      @data = Issue.by_assigned_to(@project, with_subprojects)
71 78
      @report_title = l(:field_assigned_to)
72 79
    when "author"
73 80
      @field = "author_id"
74
      @rows = @project.users.sorted
81
## begin patch private role
82
      #@rows = @project.users.sorted
83
      @rows = @project.users.visible.sorted
84
## end patch private role
75 85
      @data = Issue.by_author(@project, with_subprojects)
76 86
      @report_title = l(:field_author)
77 87
    when "subproject"
app/controllers/users_controller.rb (working copy)
73 73

  
74 74
  def show
75 75
    unless @user.visible?
76
      render_404
76
## begin patch private role (revert revision 13584 - if user with private role (or non-member?) acts on issue, user should be visible)
77
      #render_404
78
      render_403
79
## end patch private role
77 80
      return
78 81
    end
79 82

  
app/models/principal.rb (working copy)
59 59
      else
60 60
        # self and members of visible projects
61 61
        active.where(
62
          "#{table_name}.id = ? OR #{table_name}.id IN (SELECT user_id FROM #{Member.table_name} WHERE project_id IN (?))",
62
## begin patch private role
63
        #"#{table_name}.id = ? OR #{table_name}.id IN (SELECT user_id FROM #{Member.table_name} WHERE project_id IN (?))",
64
        "#{table_name}.id = ? OR #{table_name}.id IN (" +
65
          "SELECT m.user_id FROM #{Member.table_name} m" +
66
          " INNER JOIN #{MemberRole.table_name} mr ON m.id = mr.member_id" +
67
          " INNER JOIN #{Role.table_name} r ON mr.role_id = r.id" +
68
          " WHERE m.project_id IN (?) AND r.name NOT LIKE 'private.%')",
69
## end patch private role
63 70
          user.id, user.visible_project_ids
64 71
        )
65 72
      end
app/models/project.rb (working copy)
549 549
  # Returns a hash of project users/groups grouped by role
550 550
  def principals_by_role
551 551
    memberships.includes(:principal, :roles).inject({}) do |h, m|
552
      m.roles.each do |r|
552
## begin patch private role
553
      #m.roles.each do |r|
554
      m.roles.non_private.each do |r|
555
## end patch private role      
553 556
        h[r] ||= []
554 557
        h[r] << m.principal
555 558
      end
......
599 602

  
600 603
    scope = Principal.
601 604
      active.
605
## begin patch private role
606
      visible.
607
## end patch private role
602 608
      joins(:members => :roles).
603 609
      where(:type => types, :members => {:project_id => id}, :roles => {:assignable => true}).
604 610
      distinct.
app/models/role.rb (working copy)
54 54
  ]
55 55

  
56 56
  scope :sorted, lambda {order(:builtin, :position)}
57
  scope :givable, lambda {order(:position).where(:builtin => 0)}
57
## begin patch private role
58
  #scope :givable, lambda {order(:position).where(:builtin => 0)}
59
  scope :givable, lambda {
60
    if User.current.admin?
61
      order(:position).where(:builtin => 0)
62
    else
63
      order(:position).non_private.where(:builtin => 0)
64
    end
65
  }
66
  scope :non_private, lambda { 
67
    if User.current.admin?
68
      all
69
    else
70
      all.where("#{table_name}.name NOT LIKE 'private.%'")
71
    end
72
  }
73
## end patch private role
58 74
  scope :builtin, (lambda do |*args|
59 75
    compare = (args.first == true ? 'not' : '')
60 76
    where("#{compare} builtin = 0")