Sha256: 2360692bf3cb14e0dc9dbccf6dc3f6c88126bdfa068580de417f2ba3a4125bb4

Contents?: true

Size: 1.66 KB

Versions: 19

Compression:

Stored size: 1.66 KB

Contents

class OrganizationsController < ArtfullyOseController
  rescue_from CanCan::AccessDenied do |exception|
    flash[:alert] = exception.message
    redirect_to root_path
  end

  def index
    if current_user.is_in_organization?
      redirect_to organization_url(current_user.current_organization)
    else
      redirect_to new_organization_url
    end
  end

  def show
    @organization = Organization.find(params[:id])
    authorize! :view, @organization
  end

  def new
    unless current_user.current_organization.new_record?
      flash[:error] = "You can only join one organization at this time."
      redirect_to organizations_url
    end

    if Organization.all.length > 0
      flash[:error] = "There is already an organization created for this installation."
    end

    @organization = Organization.new
  end

  def create
    if Organization.all.length > 0
      flash[:error] = "There is already an organization created for this installation."
      redirect_to new_organization_path and return
    end

    @organization = Organization.new(params[:organization])

    if @organization.save
      @organization.users << current_user
      redirect_to organizations_url, :notice => "#{@organization.name} has been created"
    else
      render :new
    end
  end

  def edit
    @organization = Organization.find(params[:id])
    authorize! :edit, @organization
  end

  def update
    @organization = Organization.find(params[:id])
    authorize! :edit, @organization

    if @organization.update_attributes(params[:organization])
      flash[:notice] = "Successfully updated #{@organization.name}."
      redirect_to @organization
    else
      render :show
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.27 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.26 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.24 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.23 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.21 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.20 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.19 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.18 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.17 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.16 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.15 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.12 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.11 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.10 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.9 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.8 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.7 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.6 app/controllers/organizations_controller.rb
artfully_ose-1.2.0.pre.5 app/controllers/organizations_controller.rb