diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 2d301d3d9..931773186 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -11,7 +11,8 @@ class Users::SettingsController < ApplicationController :tutorial, :reset_tutorial, :notifications_settings, - :user_current_organization + :user_current_organization, + :destroy_user_organization ] before_action :check_organization_permission, only: [ @@ -392,7 +393,7 @@ class Users::SettingsController < ApplicationController # the user from the organization) new_owner = current_user end - + reset_user_current_organization(@user_org) @user_org.destroy(new_owner) end rescue Exception @@ -598,4 +599,11 @@ class Users::SettingsController < ApplicationController UserNotification.create(notification: notification, user: target_user) end end + + def reset_user_current_organization(user_org) + ids = user_org.user.organizations_ids + ids -= [user_org.organization.id] + user_org.user.current_organization_id = ids.first + user_org.user.save + end end diff --git a/app/models/user.rb b/app/models/user.rb index 809389459..8227d8b90 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -259,6 +259,10 @@ class User < ActiveRecord::Base .uniq end + def organizations_ids + organizations.pluck(:id) + end + protected def time_zone_check