lib/softwear/auth/standard_model.rb in softwear-lib-3.1.5 vs lib/softwear/auth/standard_model.rb in softwear-lib-3.3.5
- old
+ new
@@ -402,10 +402,20 @@
objects = JSON.parse(json).map(&method(:new))
objects.each { |u| u.instance_variable_set(:@persisted, true) }
end
# ====================
+ # Returns array of all users in the given group
+ # ====================
+ def of_group(group_code)
+ json = validate_response query "ofgroup #{Figaro.env.hub_app_name} #{group_code}"
+
+ objects = JSON.parse(json).map(&method(:new))
+ objects.each { |u| u.instance_variable_set(:@persisted, true) }
+ end
+
+ # ====================
# Given a valid signin token:
# Returns the authenticated user for the given token
# Given an invalid signin token:
# Returns false
# ====================
@@ -430,11 +440,11 @@
# ============================= INSTANCE METHODS ======================
REMOTE_ATTRIBUTES = [
:id, :email, :first_name, :last_name,
- :roles, :profile_picture_url,
+ :roles, :groups, :profile_picture_url,
:default_view, :rights
]
REMOTE_ATTRIBUTES.each(&method(:attr_accessor))
attr_reader :persisted
@@ -500,9 +510,17 @@
if @roles.nil?
query("role #{Figaro.env.hub_app_name} #{id} #{wanted_roles.join(' ')}") == 'yes'
else
wanted_roles.any? { |r| @roles.include?(r.to_s) }
+ end
+ end
+
+ def group?(group)
+ if @groups.nil?
+ query("group #{Figaro.env.hub_app_name} #{id} #{group}") == 'yes'
+ else
+ @groups.include?(group)
end
end
end
end
end