cirandas.net

ref: master

app/controllers/admin/environment_role_manager_controller.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class EnvironmentRoleManagerController < AdminController
  protect 'manage_environment_roles', :environment

  def index
    @admins = Person.where('role_assignments.resource_type = ?', 'Environment').includes(:role_assignments)
  end

  def change_roles
    @admin = Person.find(params[:id])
    @roles = Role.all.select{ |r| r.has_kind?(:environment) }
  end

  def update_roles
    @roles = params[:roles] ? Role.find(params[:roles]) : []
    @person = Person.find(params[:person])
    if @person.define_roles(@roles, environment)
      session[:notice] = _('Roles successfuly updated')
    else
      session[:notice] = _('Couldn\'t change the roles')
    end
    redirect_to :action => :index
  end

  def change_role
    @roles = Role.all.select{ |r| r.has_kind?(:environment) }
    @admin = Person.find(params[:id])
    @associations = @admin.find_roles(environment)
  end

  def add_role
    @person = Person.find(params[:person])
    @role = Role.find(params[:role])
    if environment.affiliate(@person, @role)
      redirect_to :action => 'index'
    else
      @admin = Person.find(params[:person])
      @roles = Role.all.select{ |r| r.has_kind?(:environment) }
      render :action => 'affiliate'
    end
  end

  def remove_role
    @association = RoleAssignment.find(params[:id])
    if @association.destroy
      session[:notice] = _('Member succefully unassociated')
    else
      session[:notice] = _('Failed to unassociate member')
    end
    redirect_to :aciton => 'index'
  end

  def unassociate
    @association = RoleAssignment.find(params[:id])
    if @association.destroy
      session[:notice] = _('Member succefully unassociated')
    else
      session[:notice] = _('Failed to unassociate member')
    end
    redirect_to :aciton => 'index'
  end

  def make_admin
    @people = Person.all
    @roles = Role.all.select{|r|r.has_kind?(:environment)}
  end
end