Class: ACL_Object
- Inherits:
-
Object
- Object
- ACL_Object
- Defined in:
- lib/ACL_Object.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#col_path ⇒ Object
readonly
Returns the value of attribute col_path.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
-
#add_membership(name, groups, ob_exists = false) ⇒ Object
adds acl object into group(s); if you know prin exists set true for prin_exists.
- #create_new(name, groups) ⇒ Object
-
#del_membership(name, groups) ⇒ Object
def add_membership.
-
#delete(name) ⇒ Object
def del_membership.
-
#find_parents(id) ⇒ Object
finds membership parrent and returns in sorted array by level, Root is first leaf is last.
- #ge(t, f) ⇒ Object
-
#initialize(connector, col_path, report = false) ⇒ ACL_Object
constructor
A new instance of ACL_Object.
-
#rename(old_name, new_name) ⇒ Object
def delete.
Constructor Details
#initialize(connector, col_path, report = false) ⇒ ACL_Object
Returns a new instance of ACL_Object.
7 8 9 10 11 |
# File 'lib/ACL_Object.rb', line 7 def initialize(connector, col_path, report = false) @connector = connector @col_path = col_path @report = report end |
Instance Attribute Details
#col_path ⇒ Object (readonly)
Returns the value of attribute col_path.
5 6 7 |
# File 'lib/ACL_Object.rb', line 5 def col_path @col_path end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
4 5 6 |
# File 'lib/ACL_Object.rb', line 4 def doc @doc end |
Instance Method Details
#add_membership(name, groups, ob_exists = false) ⇒ Object
adds acl object into group(s); if you know prin exists set true for prin_exists
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 |
# File 'lib/ACL_Object.rb', line 84 def add_membership(name, groups, ob_exists = false) if(ob_exists || exists?(name))#, "#{@doc}//Individual[@id=\"#{name}\"]")) for group in groups if(!exists?(group))#, "#{@doc}//Group[@id=\"#{group}\"]")) raise RubyACLException.new(self.class.name, __method__, "Failed to add membership. Group \"#{group}\" does not exist.", 113), caller end query = "#{@doc}//node()[@id=\"#{name}\"]/membership/mgroup[@idref=\"#{group}\"]" handle = @connector.execute_query(query) hits = @connector.get_hits(handle) if(hits == 0) #protection against cycle in membership if(find_parents(group).find_index(name).nil?) expr = "<mgroup idref=\"#{group}\"/>" expr_single = "#{@doc}//node()[@id=\"#{name}\"]/membership" @connector.update_insert(expr, "into", expr_single) else raise RubyACLException.new(self.class.name, __method__, "Failed to add membership. Membership is in cycle.", 118), caller end else puts "Membership already exists." if @report end end else raise RubyACLException.new(self.class.name, __method__, "Failed to add membership. #{self.class.name} \"#{name}\" does not exist.", 114), caller end return name rescue => e raise e end |
#create_new(name, groups) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ACL_Object.rb', line 49 def create_new(name, groups) bool=true if(name == nil || name == '') bool = false raise RubyACLException.new(self.class.name, __method__, "Name is empty", 110), caller end if(exists?(name)) bool = false raise RubyACLException.new(self.class.name, __method__, "#{self.class.name} \"#{name}\" already exist(s)", 111), caller end if(bool) expr = generate_expr(name) expr_loc = "#{@doc}//#{self.class.name}s/#{self.class.name}[last()]" @connector.update_insert(expr, "following", expr_loc) if(exists?(name)) puts "New #{self.class.name} \"#{name}\" created." if @report else raise RubyACLException.new(self.class.name, __method__, "#{self.class.name} \"#{name}\" was not able to create", 112), caller end end if(groups.length > 0) add_membership(name, groups, true) end return name rescue XMLRPC::FaultException => e raise e rescue => e raise e end |
#del_membership(name, groups) ⇒ Object
def add_membership
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ACL_Object.rb', line 117 def del_membership(name, groups) #deletes prin_name from group(s) if(exists?(name)) for group in groups expr = "#{@doc}//#{self.class.name}s/descendant::*[@id=\"#{name}\"]/membership/mgroup[@idref=\"#{group}\"]" @connector.update_delete(expr) #end if(!exists?(group)) raise RubyACLException.new(self.class.name, __method__, "Failed to delete membership. Group \"#{group}\" does not exist.", 115), caller end end else raise RubyACLException.new(self.class.name, __method__, "Failed to delete membership. #{self.class.name} \"#{name}\" does not exist.", 116), caller end return name rescue => e raise e end |
#delete(name) ⇒ Object
def del_membership
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ACL_Object.rb', line 137 def delete(name) if(exists?(name)) #deletes ACL_Object expr = "#{@doc}//#{self.class.name}s/descendant::*[@id=\"#{name}\"]" @connector.update_delete(expr) #deletes references at ACL_Object expr = "#{@doc}//node()[@idref=\"#{name}\"]" @connector.update_delete(expr) #deletes ACE mentioning ACL_Object expr = "doc(\"#{@col_path}acl.xml\")//node()[@idref=\"#{name}\"]/parent::node()" @connector.update_delete(expr) else raise RubyACLException.new(self.class.name, __method__, "Failed to delete #{self.class.name}. #{self.class.name} \"#{name}\" does not exist.", 117), caller end return name rescue => e raise e end |
#find_parents(id) ⇒ Object
finds membership parrent and returns in sorted array by level, Root is first leaf is last. e.g. dog’s parrent is mammal.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/ACL_Object.rb', line 206 def find_parents(id) query = "#{@doc}//node()[@id=\"#{id}\"]/membership/*/string(@idref)" ids = [] handle = @connector.execute_query(query) hits = @connector.get_hits(handle) hits.times { |i| id_ref = @connector.retrieve(handle, i) if(id_ref=="") next #for unknown reason eXist returns 1 empty hit even any exists therefore unite is skipped (e.g. //node()[@id="all"]/membership/*/string(@idref) end ids = find_parents(id_ref) | ids | [id_ref] #unite arrays } return ids rescue => e raise e end |
#ge(t, f) ⇒ Object
195 196 197 198 199 200 201 |
# File 'lib/ACL_Object.rb', line 195 def ge(t, f) if(t >= f) return true else return false end end |
#rename(old_name, new_name) ⇒ Object
def delete
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/ACL_Object.rb', line 157 def rename(old_name, new_name) if(!exists?(new_name)) expr = "#{@doc}//node()[@id=\"#{old_name}\"]/@id" expr_single = "\"#{new_name}\"" @connector.update_value(expr, expr_single) expr = "#{@doc}//node()[@idref=\"#{old_name}\"]/@idref" expr_single = "\"#{new_name}\"" @connector.update_value(expr, expr_single) expr = "doc(\"#{@col_path}acl.xml\")//node()[@idref=\"#{old_name}\"]/@idref" expr_single = "\"#{new_name}\"" @connector.update_value(expr, expr_single) query = "doc(\"#{@col_path}acl.xml\")//node()[@id=\"#{old_name}\"]" handle = @connector.execute_query(query) hits = @connector.get_hits(handle) query = "#{@doc}//node()[@id=\"#{old_name}\"]" handle = @connector.execute_query(query) hits += @connector.get_hits(handle) if(hits == 0) puts "Rename succeeded." if @report else raise RubyACLException.new(self.class.name, __method__, "Failed to rename", 120), caller end else raise RubyACLException.new(self.class.name, __method__, "Failed to rename #{self.class.name}. #{self.class.name} \"#{new_name}\" already exists.", 119), caller end return old_name rescue XMLRPC::FaultException => e raise e rescue => e raise e end |