lib/softwear/auth/standard_model.rb in softwear-lib-1.7.1 vs lib/softwear/auth/standard_model.rb in softwear-lib-1.7.2

- old
+ new

@@ -403,11 +403,11 @@ # ============================= INSTANCE METHODS ====================== REMOTE_ATTRIBUTES = [ :id, :email, :first_name, :last_name, - :profile_picture_url + :roles, :profile_picture_url ] REMOTE_ATTRIBUTES.each(&method(:attr_accessor)) attr_reader :persisted alias_method :persisted?, :persisted @@ -463,9 +463,19 @@ "#{@first_name} #{@last_name}" end def valid_password?(pass) query("pass #{id} #{pass}") == 'yes' + end + + def role?(*wanted_roles) + return true if wanted_roles.empty? + + if @roles.nil? + query("role #{id} #{wanted_roles.join(' ')}") == 'yes' + else + wanted_roles.any? { |r| @roles.include?(r) } + end end end end end