Skip to content

Commit

Permalink
Mise à jour par un membre d'une organisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yalaeddin committed Dec 15, 2023
1 parent 09088fc commit 4d2f357
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ en:
button_delete_all: "Delete all"
organization_delete_all_confirm: "Are you sure to remove all members of this organization?"
inherited_from_parent_project: "Inherited from parent project"
field_updated_by_organization: Updated by member of
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ fr:
no_missing_organizations: "Aucune organisation à ajouter depuis le LDAP pour ce chemin : %{path}"
inherited_from_parent_project: "Hérité du projet parent"
field_top_department_in_ldap: "Département racine dans le LDAP"
field_updated_by_organization: Mise à jour par un membre de
24 changes: 24 additions & 0 deletions lib/redmine_organizations/patches/issue_query_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class IssueQuery < Query
self.available_columns << QueryColumn.new(:author_organization, :groupable => false) if self.available_columns.select { |c| c.name == :author_organization }.empty?
self.available_columns << QueryColumn.new(:updated_by_organization, :sortable => "#{Journal.table_name}.created_on",
:default_order => 'desc', :groupable => true) if self.available_columns.select { |c| c.name == :updated_by_organization }.empty?
end

module PluginOrganizations
Expand All @@ -24,6 +26,10 @@ def initialize_available_filters
:type => :list_optional,
:values => lambda {organization_values},
:label => :field_author_organization
add_available_filter "updated_by_organization",
:type => :list_optional,
:values => lambda {organization_values},
:label => :field_updated_by_organization
end

def sql_for_author_organization_field(field, operator, value)
Expand All @@ -46,6 +52,24 @@ def sql_for_author_organization_field(field, operator, value)
end
end

def sql_for_updated_by_organization_field(field, operator, value)
if value.delete('mine')
value.push User.current&.organization&.id&.to_s
end
cond = value.any? ?
"#{User.table_name}.organization_id IN (" + value.collect{|val| "'#{self.class.connection.quote_string(val)}'"}.join(",") + ")" :
"1=0"

neg = (operator == '!' ? 'NOT' : '')

subquery = "SELECT 1 FROM #{Journal.table_name}" +
" WHERE #{Journal.table_name}.journalized_type='Issue' AND #{Journal.table_name}.journalized_id=#{Issue.table_name}.id" +
" AND (journals.user_id IN (SELECT DISTINCT #{User.table_name}.id FROM #{User.table_name} WHERE #{cond}))" +
" AND (#{Journal.visible_notes_condition(User.current, :skip_pre_condition => true)})"

"#{neg} EXISTS (#{subquery})"
end

def organization_values
organization_values = []
if User.current.logged?
Expand Down
96 changes: 96 additions & 0 deletions spec/models/issue_query_patch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
require "spec_helper"

describe "IssueQueryPatch" do
fixtures :organizations, :users, :roles, :projects, :members, :trackers

context "should filter issues with updated_by_organization" do
before do
@org = Organization.create(:name => "Team C")
@user = User.generate!
@user.update_attribute(:organization_id, @org.id)
end

def find_issues_with_query(query)
Issue.joins(:status, :tracker, :project, :priority).where(
query.statement
).to_a
end

it "Should have updated_by_organization in available_filters" do
query = IssueQuery.new(:name => '_')
expect(query.available_filters.keys).to include('updated_by_organization')
end

it "operator equal =, one organization" do
Journal.create!(:user_id => @user.id, :journalized => Issue.find(2), :notes => 'Notes')
Journal.create!(:user_id => @user.id, :journalized => Issue.find(3), :notes => 'Notes')
Journal.create!(:user_id => 2, :journalized => Issue.find(4), :notes => 'Notes')

query = IssueQuery.new(:name => '_')
filter_name = "updated_by_organization"
query.filters = { filter_name => {:operator => '=', :values => [@org.id.to_s] }}

expect(find_issues_with_query(query).map(&:id).sort).to include([2, 3])
end

it "operator equal ! , one organization" do
Journal.create!(:user_id => @user.id, :journalized => Issue.find(2), :notes => 'Notes')
Journal.create!(:user_id => @user.id, :journalized => Issue.find(3), :notes => 'Notes')
Journal.create!(:user_id => 2, :journalized => Issue.find(4), :notes => 'Notes')

query = IssueQuery.new(:name => '_')
filter_name = "updated_by_organization"
query.filters = { filter_name => {:operator => '!', :values => [@org.id.to_s] }}

expect(find_issues_with_query(query).map(&:id).sort).to_not include([2, 3])
end

it "operator equal = , multi organizations" do
user_test = User.find(2)
org_test = Organization.find(2)
user_test.update_attribute(:organization_id, org_test.id)

Journal.create!(:user_id => @user.id, :journalized => Issue.find(2), :notes => 'Notes')
Journal.create!(:user_id => @user.id, :journalized => Issue.find(3), :notes => 'Notes')
Journal.create!(:user_id => user_test.id, :journalized => Issue.find(4), :notes => 'Notes')

query = IssueQuery.new(:name => '_')
filter_name = "updated_by_organization"
query.filters = { filter_name => {:operator => '=', :values => [@org.id.to_s, org_test.id.to_s] }}

expect(find_issues_with_query(query).map(&:id).sort).to include(2, 3, 4)
end

it "operator equal ! , multi organizations" do
user_test = User.find(2)
org_test = Organization.find(2)
user_test.update_attribute(:organization_id, org_test.id)

Journal.create!(:user_id => @user.id, :journalized => Issue.find(2), :notes => 'Notes')
Journal.create!(:user_id => @user.id, :journalized => Issue.find(3), :notes => 'Notes')
Journal.create!(:user_id => user_test.id, :journalized => Issue.find(4), :notes => 'Notes')

query = IssueQuery.new(:name => '_')
filter_name = "updated_by_organization"
query.filters = { filter_name => {:operator => '=', :values => [@org.id.to_s, org_test.id.to_s] }}

expect(find_issues_with_query(query).map(&:id).sort).to_not include([2, 3, 4])
end

it "Should ignore private notes that are not visible" do
Journal.create!(:user_id => @user.id, :journalized => Issue.find(2), :notes => 'Notes', :private_notes => true)
Journal.create!(:user_id => @user.id, :journalized => Issue.find(3), :notes => 'Notes')

query = IssueQuery.new(:name => '_')
filter_name = "updated_by_organization"
query.filters = {filter_name => {:operator => '=', :values => [@org.id.to_s]}}

expect(find_issues_with_query(query).map(&:id).sort).to eq([2, 3])

User.current = User.anonymous
query.filters = {filter_name => {:operator => '=', :values => [@org.id.to_s]}}

expect(find_issues_with_query(query).map(&:id).sort).to eq([3])
end
end
end

0 comments on commit 4d2f357

Please sign in to comment.