Class: RequestRefinery::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/request_refinery/user.rb

Instance Method Summary collapse

Instance Method Details

#initialize_usernameObject



21
22
23
# File 'app/models/request_refinery/user.rb', line 21

def initialize_username
  self.username = self.email if self.username.blank? or User.where(username:self.username).count > 0
end

#permission_stringsObject



46
47
48
# File 'app/models/request_refinery/user.rb', line 46

def permission_strings
  self.permissions.collect{|x| x.name}
end

#permission_symsObject



42
43
44
# File 'app/models/request_refinery/user.rb', line 42

def permission_syms
  self.permissions.collect{|x| x.name.to_sym}
end

#permissionsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/request_refinery/user.rb', line 25

def permissions
  # get permissions from Permissions and Roles, account for the :all permission
  p = super
  self.roles.each{|x| p += x.permissions}  # parse permissions from the user's roles
  p_a = p.to_a
  (p_a = Permission.all.to_a) if p.any? {|x| x.name == "all"}  # if they have the all permissions, give them all permissions

  # get restrictions
  r = self.restrictions
  r_a = r.to_a

  # remove restrictions from the permissions
  p_s = Set.new(p_a) - Set.new(r_a)

  return p_s.to_a
end