]>
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 :bigint(8) 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 :bigint(8)
13 # user_id :bigint(8) not null
14 # web_push_subscription_id :bigint(8)
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 self.access_token = Doorkeeper::AccessToken.create!(access_token_attributes
)
76 def access_token_attributes
78 application_id
: Doorkeeper
::Application.find_by(superapp
: true)&.id
,
79 resource_owner_id
: user_id
,
80 scopes
: 'read write follow',
81 expires_in
: Doorkeeper
.configuration
.access_token_expires_in
,
82 use_refresh_token
: Doorkeeper
.configuration
.refresh_token_enabled
?,
This page took 0.090497 seconds and 4 git commands to generate.