Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions .github/workflows/5_1_3.yml
Original file line number Diff line number Diff line change
@@ -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 '<policymap>' > policy.xml
echo '<policy domain="coder" rights="read | write" pattern="PDF" />' >> policy.xml
echo '</policymap>' >> 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
10 changes: 9 additions & 1 deletion app/controllers/organizations/managers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/organizations/team_leaders_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/_organization_informations.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<% managed_organizations.each do |organization| %>
<li>
<%= 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' %>
</li>
<% end %>
</ul>
Expand All @@ -70,6 +71,7 @@
<% team_leader_organizations.each do |organization| %>
<li>
<%= 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' %>
</li>
<% end %>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module RedmineOrganizations::Patches
module UsersControllerPatch

def create

if params[:back_url].present?
Expand Down
11 changes: 11 additions & 0 deletions spec/controllers/managers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/controllers/team_leaders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion spec/controllers/users_controller_patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@

expect(response).to have_http_status(:redirect)
end

end
end
2 changes: 2 additions & 0 deletions spec/fixtures/organization_team_leaders.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions spec/support/login_user_spec_helpers.rb
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions spec/system/user_system_spec.rb
Original file line number Diff line number Diff line change
@@ -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