Module: NonGrata::Persona

Defined in:
lib/non_grata/persona.rb

Instance Method Summary collapse

Instance Method Details

#authorization_schemeObject



29
30
31
# File 'lib/non_grata/persona.rb', line 29

def authorization_scheme
    :main
end

#can?(privilege, resource) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
# File 'lib/non_grata/persona.rb', line 4

def can?(privilege, resource)
    user_role = get_role
    return false unless user_role
    user_role.can?(privilege, resource)
end

#get_roleObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/non_grata/persona.rb', line 10

def get_role
    if get_scheme.is_declaritive?
        user_role = authorization_role
        return user_role if user_role.is_a? Role
        return get_scheme.roles(user_role) if user_role.is_a? Symbol
        return get_scheme.roles(user_role.to_sym) if user_role.is_a? String
    end
    if get_scheme.is_dynamic?
        NonGrata::AuthorizationRole.find_by(name: authorization_role.to_s, scheme_name: authorization_scheme.to_s)
    end
end

#get_schemeObject



22
23
24
25
26
27
# File 'lib/non_grata/persona.rb', line 22

def get_scheme 
    user_scheme = authorization_scheme
    return user_scheme if user_scheme.is_a? NonGrata::Scheme
    return  NonGrata::Authorization.schemes(user_scheme) if user_scheme.is_a? Symbol
    return  NonGrata::Authorization.schemes(user_scheme.to_sym) if user_scheme.is_a? String
end

#grant_role(role_p) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/non_grata/persona.rb', line 33

def grant_role(role_p)
    role = role_p if role_p.is_a? NonGrata::AuthorizationRole
     
    if role.scheme.is_declaritive? 
        raise "Can not grant a role from a declaritive scheme."
    end
    self.authorization_role = role.name
    self.authorization_scheme = role.scheme
end