Skip to content

Commit

Permalink
visible private issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tkusukawa committed Dec 1, 2018
1 parent b47221e commit 81395dd
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lib/custom_users_as_assignees/issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,47 @@ module IssuePatch
def self.included(base)
base.send :include, InstanceMethods
base.send :has_many, :customized, :class_name => 'CustomValue', :foreign_key => 'customized_id'
base.extend ClassMethods
base.class_eval do
alias_method_chain :notified_users, :custom_users
alias_method_chain :visible?, :custom_users
class << self
alias_method_chain :visible_condition, :custom_users
end
end
end

module ClassMethods
def visible_condition_with_custom_users(user, options={})

user_ids = []
if user.logged?
user_ids = [user.id] + user.groups.map(&:id).compact
end

prj_clause = nil
if !options.nil? && !options[:project].nil?
prj_clause = " #{Project.table_name}.id = #{options[:project].id}"
if options[:with_subprojects]
prj_clause << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})"
end
end

issues_clause = ""
unless user_ids.empty?
issues_clause << "#{Issue.table_name}.id in ("
issues_clause << "SELECT cv.customized_id"
issues_clause << " FROM #{CustomField.table_name} AS cf"
issues_clause << " INNER JOIN #{CustomValue.table_name} AS cv"
issues_clause << " ON cv.custom_field_id = cf.id"
issues_clause << " AND cv.customized_type = 'Issue'"
issues_clause << " AND cv.value in (#{user_ids.join(',')})"
issues_clause << " WHERE cf.field_format = 'user'"
issues_clause << ")"
issues_clause << " AND (#{prj_clause})" if prj_clause
end

"( #{visible_condition_without_custom_users(user, options)} OR (#{issues_clause})) "
end
end

Expand Down Expand Up @@ -56,6 +95,20 @@ def notified_users_with_custom_users
notified += notified_custom_users
notified.uniq
end

def visible_with_custom_users?(usr=nil)
visible = visible_without_custom_users?(usr)
return true if visible

u = usr
u ||= User.current
if u.logged?
custom_users().each do |custom_user|
return true if custom_user.id == u.id
end
end
return visible
end
end
end
end

0 comments on commit 81395dd

Please sign in to comment.