Class: Person

Inherits:
Sequel::Model
  • Object
show all
Defined in:
app/models/person.rb

Class Method Summary collapse

Class Method Details

.id_from_token(token) ⇒ Object


16
17
18
19
20
21
22
23
# File 'app/models/person.rb', line 16

def self.id_from_token(token)
  begin
    self.where(access_token: token).get(:id)
  rescue Sequel::DatabaseError => err
    # return nil if token is malformed UUID
    raise err unless err.wrapped_exception.is_a? PG::InvalidTextRepresentation
  end
end

.teacher?(username) ⇒ Boolean

FIXME: this should be put somewhere else so we don't have dependency on other model see also ApiHelper#user_allowed?

Returns:

  • (Boolean)

10
11
12
13
14
# File 'app/models/person.rb', line 10

def self.teacher?(username)
  DB.select(1)
    .where(Parallel.where(:teacher_ids.pg_array.contains([username])).exists)
    .any?
end