private_role_redmine_3.0.patch

Wim DePreter, 2015-03-18 11:21

Download (5.74 KB)

View differences:

app/controllers/reports_controller.rb (working copy)
24 24
    @versions = @project.shared_versions.sort
25 25
    @priorities = IssuePriority.all.reverse
26 26
    @categories = @project.issue_categories
27
    @assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort
28
    @authors = @project.users.sort
27
    ## begin patch private role
28
    #@assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users).sort
29
    @assignees = (Setting.issue_group_assignment? ? @project.principals : @project.users.visible).sort
30
    #@authors = @project.users.sort
31
    @authors = @project.users.visible.sort
32
    ## end patch private role
29 33
    @subprojects = @project.descendants.visible
30 34

  
31 35
    @issues_by_tracker = Issue.by_tracker(@project)
......
40 44
  end
41 45

  
42 46
  def issue_report_details
47
    ## begin patch private role
43 48
    case params[:detail]
49
    when "assigned_to", "author"
50
      unless User.current.admin?
51
        all_users = @project.users.active
52
        visible_users = all_users.visible
53
        if all_users.count != visible_users.count
54
          ## report/assigned_to and report/author contains all users 
55
          render_404
56
          return
57
        end 
58
      end
59
    end
60
    ## end patch private role
61

  
62
    case params[:detail]
44 63
    when "tracker"
45 64
      @field = "tracker_id"
46 65
      @rows = @project.trackers
app/controllers/users_controller.rb (working copy)
60 60
  end
61 61

  
62 62
  def show
63
    unless @user.visible?
64
      render_404
65
      return
66
    end
63
    ## begin patch private role (revert revision 13584 - if user with private role (or non-member?) acts on issue, user should be visible)
64
    #unless @user.visible?
65
    #  render_404
66
    #  return
67
    #end
68
    ## end patch private role
67 69

  
68 70
    # show projects based on current user visibility
69 71
    @memberships = @user.memberships.where(Project.visible_condition(User.current)).to_a
70 72

  
73
    ## begin patch private role (revert revision 13584)
74
    unless User.current.admin?
75
      if !@user.active? || (@user != User.current  && @memberships.empty? && events.empty?)
76
        render_404
77
        return
78
      end
79
    end
80
    ## end patch private role
81

  
71 82
    respond_to do |format|
72 83
      format.html {
73 84
        events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
app/models/principal.rb (working copy)
55 55
        active
56 56
      else
57 57
        # self and members of visible projects
58
        active.where("#{table_name}.id = ? OR #{table_name}.id IN (SELECT user_id FROM #{Member.table_name} WHERE project_id IN (?))",
58
        ## begin patch private role
59
        #active.where("#{table_name}.id = ? OR #{table_name}.id IN (SELECT user_id FROM #{Member.table_name} WHERE project_id IN (?))",
60
        active.where("#{table_name}.id = ? OR #{table_name}.id IN (" +
61
          "SELECT m.user_id FROM #{Member.table_name} m" +
62
          " INNER JOIN #{MemberRole.table_name} mr ON m.id = mr.member_id" +
63
          " INNER JOIN #{Role.table_name} r ON mr.role_id = r.id" +
64
          " WHERE m.project_id IN (?) AND r.name NOT LIKE 'private.%')",
65
        ## end patch private role
59 66
          user.id, user.visible_project_ids
60 67
        )
61 68
      end
app/models/project.rb (working copy)
31 31
  has_many :time_entry_activities
32 32
  has_many :members,
33 33
           lambda { joins(:principal, :roles).
34
                    where("#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}") }
34
                    ## begin patch private role
35
                    #where("#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}")}
36
                    where("#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE} AND #{Role.table_name}.name NOT LIKE 'private.%'")}
37
                    ## end patch private role
35 38
  has_many :memberships, :class_name => 'Member'
36 39
  has_many :member_principals,
37 40
           lambda { joins(:principal).
......
492 495

  
493 496
    @assignable_users ||= Principal.
494 497
      active.
498
      ## begin patch private role
499
      visible.
500
      ## end patch private role
495 501
      joins(:members => :roles).
496 502
      where(:type => types, :members => {:project_id => id}, :roles => {:assignable => true}).
497 503
      uniq.
app/models/role.rb (working copy)
45 45
  ]
46 46

  
47 47
  scope :sorted, lambda { order(:builtin, :position) }
48
  scope :givable, lambda { order(:position).where(:builtin => 0) }
48
  ## begin patch private role
49
  #scope :givable, lambda { order(:position).where(:builtin => 0) }
50
  scope :givable, lambda { 
51
    if User.current.admin?
52
      order(:position).where(:builtin => 0)
53
    else 
54
      order(:position).
55
      where("#{table_name}.name NOT LIKE 'private.%'").
56
      where(:builtin => 0)
57
    end
58
  }
59
  ## end patch private role
49 60
  scope :builtin, lambda { |*args|
50 61
    compare = (args.first == true ? 'not' : '')
51 62
    where("#{compare} builtin = 0")