Class: Permission
Overview
Defines which views and which blocks of that view are available Each user can have different Permissions, which can be recursive as well.
A permission is either
-
an action, which is given as a ViewName.Block.Label syntax
-
a permission-name, which is resolved recursively
Every “name” has a permission to
-
view: that is, display things
-
change: that is, modify the parameters
-
allow: that is, add permissions to other people
Class Method Summary collapse
- .add(name, view, parent = '') ⇒ Object
- .can(session, view) ⇒ Object
- .can_view(permission, view) ⇒ Object
- .clear ⇒ Object
-
.get_session(data) ⇒ Object
Get session.
- .getViewParent(view) ⇒ Object
- .has_role(permission, role) ⇒ Object
- .list ⇒ Object
- .session_add(session, perm) ⇒ Object
- .session_remove(session) ⇒ Object
- .views(permissions) ⇒ Object
-
.which(*data) ⇒ Object
Try to find out what the permissions are, should be changed!.
Class Method Details
.add(name, view, parent = '') ⇒ Object
29 30 31 32 |
# File 'lib/qooxview/helpers/permission.rb', line 29 def self.add( name, view, parent = '' ) @@view[ name.to_s ] = view.split(',') @@parent[ name.to_s ] = parent.split(',') end |
.can(session, view) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/qooxview/helpers/permission.rb', line 67 def self.can( session, view ) dputs( 0 ){ "Deprecated - #{caller.inspect}" } exit # If the list is not initialized, then everybody can do everything! if list.size == 0 return true end dputs( 4 ){ "@@sessions is #{@@sessions.inspect}" } = @@sessions[session.to_s] if not or .length == 0 = 'default' end self.can_view( , view ) end |
.can_view(permission, view) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/qooxview/helpers/permission.rb', line 84 def self.can_view( , view ) # dputs_func action = view.to_s.gsub( /^View\./, '' ) dputs( 4 ){ "Does #{.inspect} allow to do #{action} knowing #{@@view.inspect} and #{@@parent.inspect}" } if not or .length == 0 = %w( default ) end .to_a.each{|p| perm_list = self.getViewParent( p.to_s ) dputs( 5 ){ "p is #{p} and perm_list is #{perm_list.inspect}" } perm_list.each{|pl| type, data = pl.split(':') dputs( 5 ){ "view = #{type} and data = #{data}" } case type when 'name' dputs( 5 ){ "Pushing #{self.getViewParent(data)}" } perm_list.push( *self.getViewParent( data ) ) when 'view' if data dputs( 5 ){ "Searching #{action} - #{data.tab_name} for #{data} - #{action.class}" } if action =~ /^#{data}$/ or action =~ /^#{data.tab_name}Tabs$/ dputs( 3 ){ "#{action} is allowed" } return true end end end } } dputs( 3 ){ "#{action} is NOT allowed" } return false end |
.clear ⇒ Object
17 18 19 20 21 |
# File 'lib/qooxview/helpers/permission.rb', line 17 def self.clear @@view = {} @@parent = {} @@sessions = {} end |
.get_session(data) ⇒ Object
Get session
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/qooxview/helpers/permission.rb', line 132 def self.get_session( data ) dputs( 0 ){ "Deprecated - #{caller.inspect}" } exit if data[0] =~ /^session_id:/ return data[0].gsub(/^session_id:/, '' ) else return nil end end |
.getViewParent(view) ⇒ Object
62 63 64 65 |
# File 'lib/qooxview/helpers/permission.rb', line 62 def self.getViewParent( view ) @@view[view].to_a.collect{|c| "view:#{c}"} + @@parent[view].to_a.collect{|c| "name:#{c}"} end |
.has_role(permission, role) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/qooxview/helpers/permission.rb', line 118 def self.has_role( , role ) .to_a.each{|perm| dputs(4){"Testing #{perm} on #{role}"} return true if role.to_s =~ /^#{perm}$/ @@parent[perm] and @@parent[perm].each{|par| dputs(4){"Testing parent #{par} on #{role}"} return true if par == role.to_s || self.has_role( par, role ) } } dputs(4){"Nothing found for #{.inspect} on #{role}"} return false end |
.list ⇒ Object
25 26 27 |
# File 'lib/qooxview/helpers/permission.rb', line 25 def self.list return @@view.keys end |
.session_add(session, perm) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/qooxview/helpers/permission.rb', line 49 def self.session_add( session, perm ) dputs( 0 ){ "Deprecated - #{caller.inspect}" } exit # dputs( 4 ){ "Adding permission for session #{session}: #{perm}" } # @@sessions[session.to_s] = perm end |
.session_remove(session) ⇒ Object
56 57 58 59 60 |
# File 'lib/qooxview/helpers/permission.rb', line 56 def self.session_remove( session ) dputs( 0 ){ "Deprecated - #{caller.inspect}" } exit # @@sessions[session.to_s] = nil end |
.views(permissions) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/qooxview/helpers/permission.rb', line 34 def self.views( ) #dputs_func dputs(5){"Permissions: #{.inspect}"} dputs(5){"Views: #{@@view.inspect}"} [].flatten.collect{|p| ret = @@view[p.to_s] @@parent[p.to_s] and ret += @@parent[p.to_s].collect{|a| self.views(a) } if not ret ret = [] end dputs(5){"Having #{ret.inspect}"} ret }.flatten.sort.uniq end |
.which(*data) ⇒ Object
Try to find out what the permissions are, should be changed!
144 145 146 |
# File 'lib/qooxview/helpers/permission.rb', line 144 def self.which( *data ) return '' end |