membership_editor_controller.rb 1.17 KB
class MembershipEditorController < MyProfileController

  before_filter :login_required

  def target
    environment
  end

  protect 'edit_profile', :profile, :only => [:index, :new_enterprise, :create_enterprise ]

  def index
    @memberships = current_user.person.enterprise_memberships
  end

  def new_enterprise
    @enterprise = Enterprise.new()
    @validation_entities = Organization.find(:all)
  end

  def create_enterprise
    @enterprise = Enterprise.new(params[:enterprise])
    @enterprise.organization_info = OrganizationInfo.new(params[:organization])
    if @enterprise.save
      @enterprise.affiliate(current_user.person, Role.find(:all, :conditions => {:name => ['owner', 'member', 'moderator']}))
      flash[:notice] = _('The enterprise was successfully created, the validation entity will cotact you as soon as your enterprise is approved')
      redirect_to :action => 'index'
    else
      flash[:notice] = _('Enterprise was not created')
      @validation_entities = Organization.find(:all)
      render :action => 'register_form'
    end
  end
  
  # Search enterprises by name or tags
  def search
    @tagged_enterprises = Enterprise.search(params[:query])
  end

end