]>
cat aescling's git repositories - mastodon.git/blob - app/models/session_activation.rb
1 # frozen_string_literal: true
2 # == Schema Information
4 # Table name: session_activations
6 # id :integer not null, primary key
7 # session_id :string not null
8 # created_at :datetime not null
9 # updated_at :datetime not null
10 # user_agent :string default(""), not null
12 # access_token_id :integer
13 # user_id :integer not null
14 # web_push_subscription_id :integer
17 class SessionActivation
< ApplicationRecord
18 belongs_to
:user, inverse_of
: :session_activations
19 belongs_to
:access_token, class_name
: 'Doorkeeper::AccessToken', dependent
: :destroy, optional
: true
20 belongs_to
:web_push_subscription, class_name
: 'Web::PushSubscription', dependent
: :destroy, optional
: true
27 @detection ||= Browser
.new(user_agent
)
38 before_create
:assign_access_token
39 before_save
:assign_user_agent
43 id
&& where(session_id
: id
).exists
?
46 def activate(**options
)
47 activation
= create!
(options
)
54 where(session_id
: id
).destroy_all
58 order('created_at desc').offset(Rails
.configuration
.x
.max_session_activations
).destroy_all
62 where('session_id != ?', id).destroy_all
69 self.user_agent = '' if user_agent.nil?
72 def assign_access_token
73 superapp = Doorkeeper::Application.find_by(superapp: true)
75 self.access_token = Doorkeeper::AccessToken.create!(application_id
: superapp
&.id
,
76 resource_owner_id
: user_id
,
77 scopes
: 'read write follow',
78 expires_in
: Doorkeeper
.configuration
.access_token_expires_in
,
79 use_refresh_token
: Doorkeeper
.configuration
.refresh_token_enabled
?)
This page took 0.082553 seconds and 4 git commands to generate.