From b31c1d0d671cb2fae7b22719ced6875bdf296e24 Mon Sep 17 00:00:00 2001 From: Yalaeddin Date: Tue, 18 Jun 2024 09:24:17 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Suppression=20des=20r=C3=B4les=20Gestionnai?= =?UTF-8?q?re=20d'organisation=20ou=20Chef=20d'=C3=A9quipe=20depuis=20la?= =?UTF-8?q?=20fiche=20d'un=20utilisateur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../patches/users_controller_patch.rb | 16 +++++++++++++++- spec/controllers/users_controller_patch_spec.rb | 14 ++++++++++++++ spec/fixtures/organization_team_leaders.yml | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/redmine_organizations/patches/users_controller_patch.rb b/lib/redmine_organizations/patches/users_controller_patch.rb index 3fe7c2e..8d71f9a 100644 --- a/lib/redmine_organizations/patches/users_controller_patch.rb +++ b/lib/redmine_organizations/patches/users_controller_patch.rb @@ -2,7 +2,7 @@ module RedmineOrganizations::Patches module UsersControllerPatch - + def create if params[:back_url].present? @@ -56,10 +56,14 @@ class UsersController < ApplicationController before_action :require_admin, :except => [:show, :new, :create] before_action :require_admin_or_manager, :only => [:new, :create] after_action :update_memberships_according_to_new_orga, only: [:update] + before_action :get_old_orga, only: [:update] private def update_memberships_according_to_new_orga + if @user.present? && @old_orga.present? && @old_orga!= @user.organization + remove_old_organization_roles + end if @user.present? && @user.errors.empty? && @@ -88,4 +92,14 @@ def update_memberships_according_to_new_orga end end end + + def get_old_orga + @old_orga = @user.organization if @user.present? + end + + def remove_old_organization_roles + filtered_managers =@user.organization_managers.where(organization_id: @old_orga.id) + filtered_managers.destroy_all + @user.organization_team_leaders.destroy_all + end end diff --git a/spec/controllers/users_controller_patch_spec.rb b/spec/controllers/users_controller_patch_spec.rb index 54b0668..e9d325a 100644 --- a/spec/controllers/users_controller_patch_spec.rb +++ b/spec/controllers/users_controller_patch_spec.rb @@ -63,5 +63,19 @@ expect(response).to have_http_status(:redirect) end + it "removes the Organization Manager or Team Leader roles when the user leaves their organization" do + user_test = User.find(2) + user_test.organization = Organization.find(2) + user_test.save + expect { + put :update, + params: + {:id => 2, + :user => {:organization_id => '1', + :orga_update_method => 'keep'}} + + }.to change{OrganizationTeamLeader.count}.by(-1) + .and change{OrganizationManager.count}.by(-1) + end end end diff --git a/spec/fixtures/organization_team_leaders.yml b/spec/fixtures/organization_team_leaders.yml index 17d3125..dc0068c 100644 --- a/spec/fixtures/organization_team_leaders.yml +++ b/spec/fixtures/organization_team_leaders.yml @@ -1,7 +1,9 @@ --- organization_team_leaders_001: + id: 1 user_id: 1 organization_id: 1 organization_team_leaders_002: + id: 2 user_id: 2 organization_id: 2 From 1d5826671d4af2a9bfedf9d1c9f96000553cc6a9 Mon Sep 17 00:00:00 2001 From: Yalaeddin Date: Tue, 18 Jun 2024 09:29:47 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Cr=C3=A9er=20le=20workflow=20pour=20Redmine?= =?UTF-8?q?=205.1.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/5_1_3.yml | 161 ++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 .github/workflows/5_1_3.yml diff --git a/.github/workflows/5_1_3.yml b/.github/workflows/5_1_3.yml new file mode 100644 index 0000000..44f5426 --- /dev/null +++ b/.github/workflows/5_1_3.yml @@ -0,0 +1,161 @@ +name: Tests 5.1.3 + +env: + PLUGIN_NAME: redmine_organizations + REDMINE_VERSION: 5.1.3 + +on: + push: + pull_request: + +jobs: + test: + name: ${{ github.workflow }} ${{ matrix.db }} ruby-${{ matrix.ruby }} + runs-on: ubuntu-latest + + strategy: + matrix: + ruby: ['3.2'] + db: ['postgres'] + fail-fast: false + + services: + postgres: + image: postgres:13 + env: + POSTGRES_DB: redmine + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout Redmine + uses: actions/checkout@v4 + with: + repository: redmine/redmine + ref: ${{ env.REDMINE_VERSION }} + path: redmine + + - name: Update package archives + run: sudo apt-get update --yes --quiet + + - name: Install package dependencies + run: > + sudo apt-get update && sudo apt-get install --yes --quiet + build-essential + cmake + libicu-dev + libpq-dev + ghostscript + gsfonts + + - name: Set up chromedriver + uses: nanasess/setup-chromedriver@master + - run: | + export DISPLAY=:99 + chromedriver --url-base=/wd/hub & + sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional + + - name: Allow imagemagick to read PDF files + run: | + echo '' > policy.xml + echo '' >> policy.xml + echo '' >> policy.xml + sudo rm /etc/ImageMagick-6/policy.xml + sudo mv policy.xml /etc/ImageMagick-6/policy.xml + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + + - name: Setup Bundler + run: gem install bundler -v '~> 1.0' + + - name: Checkout dependencies - Base RSpec plugin + uses: actions/checkout@v4 + with: + repository: jbbarth/redmine_base_rspec + path: redmine/plugins/redmine_base_rspec + + - name: Prepare Redmine source + working-directory: redmine + run: | + # TODO Remove the following line when https://www.redmine.org/issues/40551 is fixed + sed -i -e 's/.*mocha.*/ gem "mocha", "2.1.0"/' Gemfile # Fix core tests not compatible with Mocha 2.2.0 + rm -f test/integration/routing/plugins_test.rb # Fix routing tests # TODO Remove this line when https://www.redmine.org/issues/38707 is fixed + sed -i '/rubocop/d' Gemfile + rm -f .rubocop* + cp plugins/redmine_base_rspec/spec/support/database-${{ matrix.db }}.yml config/database.yml + + - name: Install Ruby dependencies + working-directory: redmine + run: | + bundle install --jobs=4 --retry=3 --without development + + - name: Generate session store secret + env: + RAILS_ENV: test + working-directory: redmine + run: | + bundle exec rake generate_secret_token + + - name: Run Redmine DB and migration tasks + env: + RAILS_ENV: test + working-directory: redmine + run: | + bundle exec rake db:create db:migrate + bundle exec rails test:scm:setup:subversion + + - name: Checkout dependencies - Base Deface plugin + uses: actions/checkout@v4 + with: + repository: jbbarth/redmine_base_deface + path: redmine/plugins/redmine_base_deface + + - name: Checkout dependencies - Base StimulusJS plugin + uses: actions/checkout@v4 + with: + repository: nanego/redmine_base_stimulusjs + path: redmine/plugins/redmine_base_stimulusjs + + - name: Checkout plugin + uses: actions/checkout@v4 + with: + path: redmine/plugins/${{ env.PLUGIN_NAME }} + + - name: Install plugins dependencies and run plugins migrations + env: + RAILS_ENV: test + working-directory: redmine + run: | + bundle install --jobs=4 --retry=3 --without development + bundle exec rake redmine:plugins:migrate + cp -i plugins/*/spec/fixtures/*yml test/fixtures/ + bundle exec rails db:fixtures:load + + - name: Run core tests + env: + RAILS_ENV: test + working-directory: redmine + run: bundle exec rails test + + - name: Run plugin tests + env: + RAILS_ENV: test + working-directory: redmine + run: bundle exec rails redmine:plugins:test NAME=${{ env.PLUGIN_NAME }} RUBYOPT="-W0" + + - name: Run uninstall test + env: + RAILS_ENV: test + working-directory: redmine + run: bundle exec rake redmine:plugins:migrate NAME=${{ env.PLUGIN_NAME }} VERSION=0 From b262e659e1a6b4a198490d8089f8adf1528006ea Mon Sep 17 00:00:00 2001 From: Yalaeddin Date: Wed, 19 Jun 2024 14:43:07 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Ajouter=20des=20liens,=20sur=20la=20fiche?= =?UTF-8?q?=20d'un=20utilisateur,=20pour=20que=20les=20admins=20puissent?= =?UTF-8?q?=20retirer=20les=20r=C3=B4les=20d'un=20utilisateur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../organizations/managers_controller.rb | 10 +++++- .../organizations/team_leaders_controller.rb | 11 +++++- .../users/_organization_informations.html.erb | 2 ++ config/routes.rb | 2 +- .../patches/users_controller_patch.rb | 14 -------- spec/controllers/managers_controller_spec.rb | 11 ++++++ .../team_leaders_controller_spec.rb | 9 +++++ .../users_controller_patch_spec.rb | 15 -------- spec/support/login_user_spec_helpers.rb | 15 ++++++++ spec/system/user_system_spec.rb | 36 +++++++++++++++++++ 10 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 spec/support/login_user_spec_helpers.rb create mode 100644 spec/system/user_system_spec.rb diff --git a/app/controllers/organizations/managers_controller.rb b/app/controllers/organizations/managers_controller.rb index 7446acb..66931f6 100644 --- a/app/controllers/organizations/managers_controller.rb +++ b/app/controllers/organizations/managers_controller.rb @@ -13,7 +13,15 @@ def create end def destroy - @organization.managers.delete(User.find(params[:manager_id])) + user = User.find(params[:manager_id]) + @organization.managers.delete(user) + + if params[:page].present? && params[:page] == "user" + respond_to do |format| + format.js { render js: "window.location.reload();" } + end + end + respond_to do |format| format.html { redirect_to edit_organization_path(@organization.identifier, tab: 'managers') } format.js diff --git a/app/controllers/organizations/team_leaders_controller.rb b/app/controllers/organizations/team_leaders_controller.rb index 6bf5b85..41e983e 100644 --- a/app/controllers/organizations/team_leaders_controller.rb +++ b/app/controllers/organizations/team_leaders_controller.rb @@ -1,6 +1,6 @@ class Organizations::TeamLeadersController < ApplicationController - before_action :find_organization_by_id, only: [:update] + before_action :find_organization_by_id, only: [:update, :destroy] before_action :require_admin_or_manager def assign_to_team_projects @@ -37,6 +37,15 @@ def assign_to_team_projects end end + def destroy + user = User.find(params[:team_leader_id]) + @organization.team_leaders.delete(user) + + respond_to do |format| + format.js { render js: "window.location.reload();" } + end + end + def update team_leaders = User.where(id: params[:team_leader_ids]) team_leaders_ids = team_leaders.map(&:id) diff --git a/app/views/users/_organization_informations.html.erb b/app/views/users/_organization_informations.html.erb index b4ce71e..0e1bf21 100644 --- a/app/views/users/_organization_informations.html.erb +++ b/app/views/users/_organization_informations.html.erb @@ -60,6 +60,7 @@ <% managed_organizations.each do |organization| %>
  • <%= link_to_organization organization %> + <%= link_to l(:button_delete), organizations_manager_path(:id => organization.id, :manager_id => @user.id, :page => "user"), :method => :delete, :remote => true, :class => 'icon icon-del' %>
  • <% end %> @@ -70,6 +71,7 @@ <% team_leader_organizations.each do |organization| %>
  • <%= link_to_organization organization %> + <%= link_to l(:button_delete), organizations_team_leader_path(:id => organization.id, :team_leader_id => @user.id), :method => :delete, :remote => true, :class => 'icon icon-del' %>
  • <% end %> diff --git a/config/routes.rb b/config/routes.rb index 2da9d04..ffd5ed0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,7 @@ get :autocomplete_for_manager end end - resources :team_leaders, only: [:update] do + resources :team_leaders, only: [:update, :destroy] do collection do put :assign_to_team_projects end diff --git a/lib/redmine_organizations/patches/users_controller_patch.rb b/lib/redmine_organizations/patches/users_controller_patch.rb index 8d71f9a..766777f 100644 --- a/lib/redmine_organizations/patches/users_controller_patch.rb +++ b/lib/redmine_organizations/patches/users_controller_patch.rb @@ -56,14 +56,10 @@ class UsersController < ApplicationController before_action :require_admin, :except => [:show, :new, :create] before_action :require_admin_or_manager, :only => [:new, :create] after_action :update_memberships_according_to_new_orga, only: [:update] - before_action :get_old_orga, only: [:update] private def update_memberships_according_to_new_orga - if @user.present? && @old_orga.present? && @old_orga!= @user.organization - remove_old_organization_roles - end if @user.present? && @user.errors.empty? && @@ -92,14 +88,4 @@ def update_memberships_according_to_new_orga end end end - - def get_old_orga - @old_orga = @user.organization if @user.present? - end - - def remove_old_organization_roles - filtered_managers =@user.organization_managers.where(organization_id: @old_orga.id) - filtered_managers.destroy_all - @user.organization_team_leaders.destroy_all - end end diff --git a/spec/controllers/managers_controller_spec.rb b/spec/controllers/managers_controller_spec.rb index 0cdaacf..c7ee613 100644 --- a/spec/controllers/managers_controller_spec.rb +++ b/spec/controllers/managers_controller_spec.rb @@ -38,6 +38,17 @@ expect(organization.managers).to include(User.find(7)) end + it "should delete manager from an organization" do + @request.session[:user_id] = 1 + expect do + delete :destroy, :params => { + :manager_id => 2, + :page => "user", + :id => 2 + }, format: :js + end.to change { OrganizationManager.count }.by(-1) + end + if Redmine::VERSION::MAJOR >= 5 it "should forbid users from sub-organization to modify managers in parents of their organization" do @request.session[:user_id] = 2 # Not Admin, member of organization #2 diff --git a/spec/controllers/team_leaders_controller_spec.rb b/spec/controllers/team_leaders_controller_spec.rb index 380e502..e9ebfa4 100644 --- a/spec/controllers/team_leaders_controller_spec.rb +++ b/spec/controllers/team_leaders_controller_spec.rb @@ -157,4 +157,13 @@ expect(Project.find(5).users).to_not include User.find(4) end + it "should delete team leader from an organization" do + @request.session[:user_id] = 1 # Admin + expect do + delete :destroy, :params => { + :team_leader_id => 2, + :id => 2 + }, format: :js + end.to change { OrganizationTeamLeader.count }.by(-1) + end end diff --git a/spec/controllers/users_controller_patch_spec.rb b/spec/controllers/users_controller_patch_spec.rb index e9d325a..391db9e 100644 --- a/spec/controllers/users_controller_patch_spec.rb +++ b/spec/controllers/users_controller_patch_spec.rb @@ -62,20 +62,5 @@ expect(response).to have_http_status(:redirect) end - - it "removes the Organization Manager or Team Leader roles when the user leaves their organization" do - user_test = User.find(2) - user_test.organization = Organization.find(2) - user_test.save - expect { - put :update, - params: - {:id => 2, - :user => {:organization_id => '1', - :orga_update_method => 'keep'}} - - }.to change{OrganizationTeamLeader.count}.by(-1) - .and change{OrganizationManager.count}.by(-1) - end end end diff --git a/spec/support/login_user_spec_helpers.rb b/spec/support/login_user_spec_helpers.rb new file mode 100644 index 0000000..e93b5a5 --- /dev/null +++ b/spec/support/login_user_spec_helpers.rb @@ -0,0 +1,15 @@ +require "spec_helper" + +def log_user(login, password) + visit '/my/page' + expect(current_path).to eq '/login' + + click_on("ou s'authentifier par login / mot de passe") + + within('#login-form form') do + fill_in 'username', with: login + fill_in 'password', with: password + find('input[name=login]').click + end + expect(current_path).to eq '/my/page' +end \ No newline at end of file diff --git a/spec/system/user_system_spec.rb b/spec/system/user_system_spec.rb new file mode 100644 index 0000000..3e9e8cb --- /dev/null +++ b/spec/system/user_system_spec.rb @@ -0,0 +1,36 @@ +require "spec_helper" +require "active_support/testing/assertions" +require_relative "../support/login_user_spec_helpers" + +RSpec.describe "/issue/id/edit", type: :system do + include ActiveSupport::Testing::Assertions + + include ApplicationHelper + include OrganizationsHelper + include ActionView::Helpers::UrlHelper + + fixtures :organizations, :users, :roles, :projects, :members, :member_roles, + :organization_managers, :organization_team_leaders + before do + log_user('admin', 'admin') + end + + it "Should display delete links for member and team leader in profile page" do + user = User.find(2) + user.organization = Organization.find(2) + user.save + + visit "/users/#{user.id}" + + organization_manager = user.organization_managers.map(&:organization).compact + team_leader_organizations = user.organization_team_leaders.map(&:organization).compact + + organization_manager.each do |organization| + expect(page).to have_link(nil, href: organizations_manager_path(id: organization.id, manager_id: user.id, page: "user")) + end + + team_leader_organizations.each do |organization| + expect(page).to have_link(nil, href: organizations_team_leader_path(id: organization.id, team_leader_id: user.id)) + end + end +end \ No newline at end of file