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
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 3fe7c2e..766777f 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?
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 54b0668..391db9e 100644
--- a/spec/controllers/users_controller_patch_spec.rb
+++ b/spec/controllers/users_controller_patch_spec.rb
@@ -62,6 +62,5 @@
expect(response).to have_http_status(:redirect)
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
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