only allow organizations to be managed by admins

This commit is contained in:
Adam Cooke
2017-04-21 10:18:24 +01:00
parent 90b90577cf
commit 46daca9aa7
10 changed files with 70 additions and 119 deletions
+8 -4
View File
@@ -1,11 +1,16 @@
class OrganizationsController < ApplicationController
before_action :admin_required, :only => [:new, :create]
before_action :require_organization_admin, :only => [:edit, :update, :delete, :destroy]
def index
@organizations = current_user.organizations.present.order(:name).to_a
if @organizations.size == 1 && params[:nrd].nil?
redirect_to organization_root_path(@organizations.first)
if current_user.admin?
@organizations = Organization.present.order(:name).to_a
else
@organizations = current_user.organizations.present.order(:name).to_a
if @organizations.size == 1 && params[:nrd].nil?
redirect_to organization_root_path(@organizations.first)
end
end
end
@@ -17,7 +22,6 @@ class OrganizationsController < ApplicationController
@organization = Organization.new(params.require(:organization).permit(:name, :permalink))
@organization.owner = current_user
if @organization.save
@organization.users << current_user
redirect_to_with_json organization_root_path(@organization)
else
render_form_errors 'new', @organization