Class: PermissionController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/permission_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_role_memberObject



102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/permission_controller.rb', line 102

def add_role_member
  @person = Person.find(params[:id])
  
  @role.people.push @person
  @role.save
  if AeUsers.cache_permissions?
    AeUsers.permission_cache.invalidate_all(@person)
  end
  
  render :partial => "role_member", :locals => {:person => @person}
end

#adminObject



5
6
7
8
# File 'app/controllers/permission_controller.rb', line 5

def admin
  @pclasses = logged_in_person.administrator_classes
  @roles = Role.find :all
end

#auto_complete_for_permission_granteeObject



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
# File 'app/controllers/permission_controller.rb', line 31

def auto_complete_for_permission_grantee
  if params[:q]
    query = params[:q].strip.downcase
    liketerm = "%#{query}%"
    terms = query.split
    
    if params[:people] == "true"
      sql = terms.collect do |t|
        "((LOWER(firstname) like ?) OR (LOWER(lastname) like ?))"
      end.join(" AND ")
      doubleterms = []
      terms.each do |t|
        doubleterms.push("%#{t}%")
        doubleterms.push("%#{t}%")
      end
      @grantees = Person.find(:all, :conditions => ([sql] + doubleterms))
      @grantees += EmailAddress.find(:all,
                                     :conditions => ["LOWER(address) like ?", liketerm]).collect do |ea|
        ea.person
      end
    else
      @grantees = []
    end

    if params[:roles] == "true"      
      @grantees += Role.find(:all,
                             :conditions => ["LOWER(name) like ?", liketerm])
    end
    
    @grantees.uniq!
  else
    @grantees = []
  end
  
  render :partial => "add_grantee"
end

#create_roleObject



91
92
93
94
95
# File 'app/controllers/permission_controller.rb', line 91

def create_role
  @role = Role.create(params[:role])
  redirect_to :action => 'edit_role', :id => @role.id
  @role.grant(logged_in_person)
end

#delete_roleObject



124
125
126
127
128
129
130
131
132
# File 'app/controllers/permission_controller.rb', line 124

def delete_role
  if AeUsers.cache_permissions?
    @role.people.each do |person|
      AeUsers.permission_cache.invalidate_all(person)
    end
  end
  @role.destroy
  render :nothing => true
end

#editObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/permission_controller.rb', line 11

def edit
  pclass = nil
  AeUsers.permissioned_classes.each do |pc|
    if pc.name == params[:klass]
      pclass = pc
      break
    end
  end
  
  if pclass.nil?
    render :inline => "<h1>Invalid class name <%= h AeUsers.permissioned_classes %></h1>"
  else
    if params[:id]
      @item = pclass.find(params[:id])
    else
      @item = pclass
    end
  end    
end

#edit_roleObject



99
100
# File 'app/controllers/permission_controller.rb', line 99

def edit_role
end

#grantObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/permission_controller.rb', line 70

def grant
  perm_params = {}
  if params[:klass] == 'Person'
    @grantee = Person.find(params[:id])
    perm_params[:person_id] = @grantee.id
  else
    @grantee = Role.find(params[:id])
    perm_params[:role_id] = @grantee.id
  end
     
  @perm = Permission.create(perm_params.update(:permission => params[:perm], :permissioned => @permissioned))
  @perm.destroy_caches
end

#remove_role_memberObject



114
115
116
117
118
119
120
121
122
# File 'app/controllers/permission_controller.rb', line 114

def remove_role_member   
  @role.people.delete(@role.people.find(params[:id]))
  @role.save
  if AeUsers.cache_permissions?
    AeUsers.permission_cache.invalidate_all(@person)
  end
  
  render :nothing => true
end

#revokeObject



85
86
87
88
89
# File 'app/controllers/permission_controller.rb', line 85

def revoke
  @perm.destroy_caches
  @perm.destroy
  render :nothing => true
end