Browse Source

Allo moving deactivated users

pull/2596/head
Kat 2 years ago
parent
commit
e422ab5ee4
  1. 16
      app/controllers/users_controller.rb
  2. 14
      app/policies/user_policy.rb
  3. 13
      spec/requests/users_controller_spec.rb

16
app/controllers/users_controller.rb

@ -56,7 +56,7 @@ class UsersController < ApplicationController
def key_contact; end
def edit
redirect_to user_path(@user) unless @user.active?
redirect_to user_path(@user) unless @user.active? || current_user.support?
end
def update
@ -182,9 +182,10 @@ class UsersController < ApplicationController
def organisation_change_confirmation
authorize @user
if params[:organisation_id].blank? || params[:log_reassignment].blank? || !Organisation.where(id: params[:organisation_id]).exists?
return redirect_to user_path(@user)
end
assigned_to_logs_count = @user.assigned_to_lettings_logs.count + @user.assigned_to_sales_logs.count
return redirect_to user_path(@user) if params[:organisation_id].blank? || !Organisation.where(id: params[:organisation_id]).exists?
return redirect_to user_path(@user) if params[:log_reassignment].blank? && assigned_to_logs_count.positive?
@new_organisation = Organisation.find(params[:organisation_id])
@log_reassignment = params[:log_reassignment]
@ -192,9 +193,10 @@ class UsersController < ApplicationController
def confirm_organisation_change
authorize @user
if log_reassignment_params[:organisation_id].blank? || log_reassignment_params[:log_reassignment].blank? || !Organisation.where(id: log_reassignment_params[:organisation_id]).exists?
return redirect_to user_path(@user)
end
assigned_to_logs_count = @user.assigned_to_lettings_logs.count + @user.assigned_to_sales_logs.count
return redirect_to user_path(@user) if log_reassignment_params[:organisation_id].blank? || !Organisation.where(id: log_reassignment_params[:organisation_id]).exists?
return redirect_to user_path(@user) if log_reassignment_params[:log_reassignment].blank? && assigned_to_logs_count.positive?
@new_organisation = Organisation.find(log_reassignment_params[:organisation_id])
@log_reassignment = log_reassignment_params[:log_reassignment]

14
app/policies/user_policy.rb

@ -10,17 +10,15 @@ class UserPolicy
@current_user == @user
end
def edit_roles?
(@current_user.data_coordinator? || @current_user.support?) && @user.active?
end
%w[
edit_roles?
edit_dpo?
edit_key_contact?
].each do |method_name|
define_method method_name do
(@current_user.data_coordinator? || @current_user.support?) && @user.active?
return true if @current_user.support?
@current_user.data_coordinator? && @user.active?
end
end
@ -30,7 +28,9 @@ class UserPolicy
edit_names?
].each do |method_name|
define_method method_name do
(@current_user == @user || @current_user.data_coordinator? || @current_user.support?) && @user.active?
return true if @current_user.support?
(@current_user == @user || @current_user.data_coordinator?) && @user.active?
end
end
@ -53,7 +53,7 @@ class UserPolicy
confirm_organisation_change?
].each do |method_name|
define_method method_name do
@current_user.support? && @user.active?
@current_user.support?
end
end

13
spec/requests/users_controller_spec.rb

@ -1715,10 +1715,11 @@ RSpec.describe UsersController, type: :request do
get "/users/#{other_user.id}/edit", headers:, params: {}
end
it "redirects to user details page" do
expect(response).to redirect_to("/users/#{other_user.id}")
follow_redirect!
expect(page).not_to have_link("Change")
it "allows editing the user" do
expect(page).to have_field("user[name]")
expect(page).to have_field("user[email]")
expect(page).to have_field("user[role]")
expect(page).to have_field("user[organisation_id]")
end
end
end
@ -2470,6 +2471,10 @@ RSpec.describe UsersController, type: :request do
context "when reassignment option is not given" do
let(:new_organisation) { create(:organisation, name: "new org") }
before do
create(:lettings_log, assigned_to: other_user)
end
it "redirects to the user page" do
get "/users/#{other_user.id}/organisation-change-confirmation?organisation_id=#{new_organisation.id}"
expect(response).to redirect_to("/users/#{other_user.id}")

Loading…
Cancel
Save