Class: Orange::UserResource
- Inherits:
-
ModelResource
- Object
- ModelResource
- Orange::UserResource
- Defined in:
- lib/orange-more/administration/resources/user_resource.rb
Instance Method Summary collapse
- #access_allowed?(packet, user) ⇒ Boolean
- #afterLoad ⇒ Object
- #find_extras(packet, mode) ⇒ Object
- #onNew(packet, opts = {}) ⇒ Object
- #onSave(packet, obj, params = {}) ⇒ Object
- #user_for(packet) ⇒ Object
Instance Method Details
#access_allowed?(packet, user) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/orange-more/administration/resources/user_resource.rb', line 9 def access_allowed?(packet, user) u = model_class.first(:open_id => user) unless u users = model_class.all # Deep open id search (take out trailing slash, etc.) return false if user.blank? id = user.gsub(/^https?:\/\//, '').gsub(/\/$/, '') matches = users.select{|u| (id == u.open_id.gsub(/^https?:\/\//, '').gsub(/\/$/, '')) } if(matches.length > 0 && matches.first.allowed?(packet)) packet.session['user.id'] = matches.first.open_id packet['user.id'] = matches.first.open_id return true else packet['user.id'] = nil packet.session['user.id'] = nil return false end end u.allowed?(packet) end |
#afterLoad ⇒ Object
5 6 7 |
# File 'lib/orange-more/administration/resources/user_resource.rb', line 5 def afterLoad orange[:admin].add_link("Settings", :resource => @my_orange_name, :text => 'Users') end |
#find_extras(packet, mode) ⇒ Object
53 54 55 |
# File 'lib/orange-more/administration/resources/user_resource.rb', line 53 def find_extras(packet, mode) {:sites => OrangeSite.all} end |
#onNew(packet, opts = {}) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/orange-more/administration/resources/user_resource.rb', line 36 def onNew(packet, opts = {}) params = opts sites = params.delete 'sites' m = model_class.new(params) m.save sites.each{|k,v| s = OrangeSite.first(:id => k); m.orange_sites << s if s} if sites m end |
#onSave(packet, obj, params = {}) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/orange-more/administration/resources/user_resource.rb', line 45 def onSave(packet, obj, params ={}) sites = params.delete 'sites' obj.update(params) obj.orange_sites = [] sites.each{|k,v| s = OrangeSite.first(:id => k); obj.orange_sites << s if s} if sites obj.save end |
#user_for(packet) ⇒ Object
32 33 34 |
# File 'lib/orange-more/administration/resources/user_resource.rb', line 32 def user_for(packet) model_class.first(:open_id => packet['user.id']) end |