mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
Update specs for new user active_until column
This commit is contained in:
parent
2f41b0dd57
commit
6839ecdbda
13 changed files with 31 additions and 20 deletions
|
|
@ -13,7 +13,7 @@ class ApiController < ApplicationController
|
|||
end
|
||||
|
||||
def authenticate_active_api_user!
|
||||
render json: { error: 'User is not active' }, status: :unauthorized unless current_api_user&.active?
|
||||
render json: { error: 'User is not active' }, status: :unauthorized unless current_api_user&.active_until&.future?
|
||||
|
||||
true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def authenticate_active_user!
|
||||
return if current_user&.active?
|
||||
return if current_user&.active_until&.future?
|
||||
|
||||
redirect_to root_path, notice: 'Your account is not active.', status: :see_other
|
||||
end
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def activate
|
||||
update(status: :active)
|
||||
update(status: :active, active_until: 1000.years.from_now)
|
||||
end
|
||||
|
||||
def sanitize_input
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ class SetActiveUntilForSelfhostedUsers < ActiveRecord::Migration[8.0]
|
|||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
return unless DawarichSettings.self_hosted?
|
||||
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
User.where.not(active_until: nil).update_all(active_until: nil)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
status { :active }
|
||||
active_until { 1000.years.from_now }
|
||||
|
||||
password { SecureRandom.hex(8) }
|
||||
|
||||
|
|
@ -25,6 +26,11 @@ FactoryBot.define do
|
|||
admin { true }
|
||||
end
|
||||
|
||||
trait :inactive do
|
||||
status { :inactive }
|
||||
active_until { 1.day.ago }
|
||||
end
|
||||
|
||||
trait :with_immich_integration do
|
||||
settings do
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ RSpec.describe User, type: :model do
|
|||
|
||||
describe '#activate' do
|
||||
context 'when self-hosted' do
|
||||
let!(:user) { create(:user, status: :inactive) }
|
||||
let!(:user) { create(:user, status: :inactive, active_until: 1.day.ago) }
|
||||
|
||||
before do
|
||||
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
|
||||
|
|
@ -39,19 +39,20 @@ RSpec.describe User, type: :model do
|
|||
|
||||
it 'activates user after creation' do
|
||||
expect(user.active?).to be_truthy
|
||||
expect(user.active_until).to be_within(1.minute).of(1000.years.from_now)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not self-hosted' do
|
||||
let!(:user) { create(:user, status: :inactive) }
|
||||
|
||||
before do
|
||||
stub_const('SELF_HOSTED', false)
|
||||
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
|
||||
end
|
||||
|
||||
xit 'does not activate user' do
|
||||
it 'does not activate user' do
|
||||
user = create(:user, status: :inactive, active_until: 1.day.ago)
|
||||
|
||||
expect(user.active?).to be_falsey
|
||||
expect(user.active_until).to be_within(1.minute).of(1.day.ago)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ RSpec.describe 'Api::V1::Overland::Batches', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ RSpec.describe 'Api::V1::Owntracks::Points', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ RSpec.describe 'Api::V1::Points', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'returns an unauthorized response' do
|
||||
|
|
@ -150,7 +150,7 @@ RSpec.describe 'Api::V1::Points', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'returns an unauthorized response' do
|
||||
|
|
@ -171,7 +171,7 @@ RSpec.describe 'Api::V1::Points', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'returns an unauthorized response' do
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ RSpec.describe 'Api::V1::Settings', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ RSpec.describe 'Settings', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'redirects to the root path' do
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ RSpec.describe '/stats', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'returns an unauthorized response' do
|
||||
|
|
@ -99,7 +99,7 @@ RSpec.describe '/stats', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'returns an unauthorized response' do
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ RSpec.describe '/trips', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'redirects to the root path' do
|
||||
|
|
@ -93,7 +93,7 @@ RSpec.describe '/trips', type: :request do
|
|||
|
||||
context 'when user is inactive' do
|
||||
before do
|
||||
user.update(status: :inactive)
|
||||
user.update(status: :inactive, active_until: 1.day.ago)
|
||||
end
|
||||
|
||||
it 'redirects to the root path' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue