From 81395dd0d4c54a3892e24d9f73bcb19ba16d860b Mon Sep 17 00:00:00 2001 From: tkusukawa Date: Sat, 1 Dec 2018 21:24:01 +0900 Subject: [PATCH 1/3] visible private issues --- lib/custom_users_as_assignees/issue_patch.rb | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/lib/custom_users_as_assignees/issue_patch.rb b/lib/custom_users_as_assignees/issue_patch.rb index 7fad840..5bdd4f9 100644 --- a/lib/custom_users_as_assignees/issue_patch.rb +++ b/lib/custom_users_as_assignees/issue_patch.rb @@ -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 @@ -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 From b42abe9c274b8cf746fca69ca421d07f9ee0e162 Mon Sep 17 00:00:00 2001 From: tkusukawa Date: Mon, 4 Feb 2019 01:10:46 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=81=AE?= =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E3=83=95=E3=82=A3=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=83=89=E3=81=AB=E3=82=B0=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=81=8C=E5=90=AB=E3=81=BE=E3=82=8C=E3=81=9F=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/custom_users_as_assignees/issue_patch.rb | 23 ++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/custom_users_as_assignees/issue_patch.rb b/lib/custom_users_as_assignees/issue_patch.rb index 5bdd4f9..db493c6 100644 --- a/lib/custom_users_as_assignees/issue_patch.rb +++ b/lib/custom_users_as_assignees/issue_patch.rb @@ -56,7 +56,26 @@ def custom_users end custom_user_ids = custom_user_values.map(&:value).flatten custom_user_ids.reject! { |id| id.blank? } - User.find(custom_user_ids) +# User.find(custom_user_ids) +# Principal.find(custom_user_ids) + return users_from_ids(custom_user_ids) + end + + def users_from_ids(ids) + users = [] + ids.each do |id| + user = User.find_by_id(id) + if user + users << user + next + end + group = Group.find_by_id(id) + if group + users += users_from_ids(group.user_ids) + next + end + end + return users end # added or removed users selected in custom fields with type 'user' @@ -76,7 +95,7 @@ def custom_users_added_or_removed custom_user_added_ids.uniq! custom_user_removed_ids.uniq! custom_user_changed_ids = (custom_user_added_ids + custom_user_removed_ids).uniq - User.find(custom_user_changed_ids) + Principal.find(custom_user_changed_ids) else [] end From b967576961a3d3c0fe4f33b00f4a9105eed76b0d Mon Sep 17 00:00:00 2001 From: tkusukawa Date: Mon, 4 Feb 2019 02:04:16 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=81=AE?= =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E3=83=95=E3=82=A3=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=83=89=E3=81=AB=E3=82=B0=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=81=8C=E5=90=AB=E3=81=BE=E3=82=8C=E3=81=9F=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/custom_users_as_assignees/issue_patch.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/custom_users_as_assignees/issue_patch.rb b/lib/custom_users_as_assignees/issue_patch.rb index db493c6..408ce0c 100644 --- a/lib/custom_users_as_assignees/issue_patch.rb +++ b/lib/custom_users_as_assignees/issue_patch.rb @@ -95,7 +95,7 @@ def custom_users_added_or_removed custom_user_added_ids.uniq! custom_user_removed_ids.uniq! custom_user_changed_ids = (custom_user_added_ids + custom_user_removed_ids).uniq - Principal.find(custom_user_changed_ids) + return users_from_ids(custom_user_changed_ids) else [] end