Merge pull request #246 from ZmagoD/zd_SCI_599

fixes error when removing user from team [SCI-599]
This commit is contained in:
Zmago Devetak 2016-10-25 11:52:44 +02:00 committed by GitHub
commit 266d1415d0
2 changed files with 14 additions and 2 deletions

View file

@ -11,7 +11,8 @@ class Users::SettingsController < ApplicationController
:tutorial, :tutorial,
:reset_tutorial, :reset_tutorial,
:notifications_settings, :notifications_settings,
:user_current_organization :user_current_organization,
:destroy_user_organization
] ]
before_action :check_organization_permission, only: [ before_action :check_organization_permission, only: [
@ -392,7 +393,7 @@ class Users::SettingsController < ApplicationController
# the user from the organization) # the user from the organization)
new_owner = current_user new_owner = current_user
end end
reset_user_current_organization(@user_org)
@user_org.destroy(new_owner) @user_org.destroy(new_owner)
end end
rescue Exception rescue Exception
@ -598,4 +599,11 @@ class Users::SettingsController < ApplicationController
UserNotification.create(notification: notification, user: target_user) UserNotification.create(notification: notification, user: target_user)
end end
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 end

View file

@ -259,6 +259,10 @@ class User < ActiveRecord::Base
.uniq .uniq
end end
def organizations_ids
organizations.pluck(:id)
end
protected protected
def time_zone_check def time_zone_check