app/controllers/kadmin/application_controller.rb in kadmin-1.0.7 vs app/controllers/kadmin/application_controller.rb in kadmin-1.0.8
- old
+ new
@@ -66,12 +66,19 @@
def scoped_all(organization_scoped_ar)
organization_scoped_ar.organization_scope(organization).all
end
def organization
- if authorized_user.present?
- @organization ||= Kadmin::Organization.find_by!(name: authorized_user.organization)
+ return @organization if authorized_user.blank?
+ return @organization if @organization.present?
+
+ if session[Kadmin::AuthController::SESSION_ORG_OVERWRITE_KEY] && authorized_user.admin?
+ @organization = Kadmin::Organization.find_by!(name: session[AuthController::SESSION_ORG_OVERWRITE_KEY])
+ else
+ @organization = Kadmin::Organization.find_by!(name: authorized_user.organization)
end
+
+ return @organization
rescue ActiveRecord::RecordNotFound
render plain: "Forbidden - organization #{authorized_user.organization} not found in DB", status: :forbidden
end
# @!group Helpers