diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml
index fba7cf12..597df91b 100644
--- a/.devcontainer/docker-compose.yml
+++ b/.devcontainer/docker-compose.yml
@@ -71,3 +71,4 @@ volumes:
dawarich_shared:
dawarich_public:
dawarich_watched:
+ dawarich_storage:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bd34526c..131d28f6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -67,6 +67,7 @@ If your hardware doesn't have enough memory to migrate the imports, you can dele
- `rake points:migrate_to_lonlat` task now also reindexes the points table.
- Fixed filling `lonlat` column for old places after reverse geocoding.
- Deleting an import now correctly recalculates stats.
+- Datetime across the app is now being displayed in human readable format, i.e 26 Dec 2024, 13:49. Hover over the datetime to see the ISO 8601 timestamp.
# 0.25.3 - 2025-03-22
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 868c72c0..ab8038cd 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -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
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 78071582..314c143c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -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
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a4a01a5e..e9045092 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -115,6 +115,17 @@ module ApplicationHelper
date.strftime('%e %B %Y')
end
+ def human_datetime(datetime)
+ return unless datetime
+
+ content_tag(
+ :span,
+ datetime.strftime('%e %b %Y, %H:%M'),
+ class: 'tooltip',
+ data: { tip: datetime.iso8601 }
+ )
+ end
+
def speed_text_color(speed)
return 'text-default' if speed.to_i >= 0
diff --git a/app/models/user.rb b/app/models/user.rb
index 344512a9..769bdcfa 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -121,7 +121,8 @@ class User < ApplicationRecord
end
def activate
- update(status: :active)
+ # TODO: Remove the `status` column in the future.
+ update(status: :active, active_until: 1000.years.from_now)
end
def sanitize_input
@@ -150,6 +151,6 @@ class User < ApplicationRecord
# rubocop:enable Metrics/MethodLength
def can_subscribe?
- !active? && !DawarichSettings.self_hosted?
+ active_until&.past? && !DawarichSettings.self_hosted?
end
end
diff --git a/app/views/exports/index.html.erb b/app/views/exports/index.html.erb
index 8f9fa865..cc48435d 100644
--- a/app/views/exports/index.html.erb
+++ b/app/views/exports/index.html.erb
@@ -37,7 +37,7 @@
<% @exports.each do |export| %>
| <%= export.name %> |
- <%= export.created_at.strftime('%Y-%m-%d %H:%M:%S') %> |
+ <%= human_datetime(export.created_at) %> |
<%= export.status %> |
<% if export.completed? %>
diff --git a/app/views/imports/_import.html.erb b/app/views/imports/_import.html.erb
index a5d93b3c..aca91fd1 100644
--- a/app/views/imports/_import.html.erb
+++ b/app/views/imports/_import.html.erb
@@ -15,7 +15,7 @@
|
<%= "#{number_with_delimiter import.points.size}" %>
|
- <%= import.created_at.strftime("%d.%m.%Y, %H:%M") %> |
+ <%= human_datetime(import.created_at) %> |
diff --git a/app/views/imports/index.html.erb b/app/views/imports/index.html.erb
index 56f136d7..54a7eb79 100644
--- a/app/views/imports/index.html.erb
+++ b/app/views/imports/index.html.erb
@@ -68,12 +68,17 @@
<%= number_with_delimiter import.reverse_geocoded_points_count %>
|
- <%= import.created_at.strftime("%d.%m.%Y, %H:%M") %> |
+ <%= human_datetime(import.created_at) %> |
<% end %>
+
+
+ <%= paginate @imports %>
+
+
<% end %>
diff --git a/app/views/places/index.html.erb b/app/views/places/index.html.erb
index 5ed9365f..fd899884 100644
--- a/app/views/places/index.html.erb
+++ b/app/views/places/index.html.erb
@@ -38,7 +38,7 @@
<% @places.each do |place| %>
| <%= place.name %> |
- <%= place.created_at.strftime('%Y-%m-%d %H:%M:%S') %> |
+ <%= human_datetime(place.created_at) %> |
<%= "#{place.lat}, #{place.lon}" %> |
<%= link_to 'Delete', place, data: { confirm: "Are you sure? Deleting a place will result in deleting all visits for this place.", turbo_confirm: "Are you sure? Deleting a place will result in deleting all visits for this place.", turbo_method: :delete }, method: :delete, class: "px-4 py-2 bg-red-500 text-white rounded-md" %>
diff --git a/app/views/points/_point.html.erb b/app/views/points/_point.html.erb
index f96f5714..6c0c238b 100644
--- a/app/views/points/_point.html.erb
+++ b/app/views/points/_point.html.erb
@@ -14,7 +14,7 @@
%>
|
<%= point.velocity %> |
- <%= point.recorded_at %> |
+ <%= human_datetime(point.recorded_at) %> |
<%= point.lat %>, <%= point.lon %> |
|
diff --git a/app/views/settings/users/index.html.erb b/app/views/settings/users/index.html.erb
index 087d0e23..dff5d2fb 100644
--- a/app/views/settings/users/index.html.erb
+++ b/app/views/settings/users/index.html.erb
@@ -26,7 +26,7 @@
<%= number_with_delimiter user.tracked_points.count %>
- <%= user.created_at.strftime('%Y-%m-%d %H:%M:%S') %>
+ <%= human_datetime(user.created_at) %>
|
<% end %>
diff --git a/bin/importmap b/bin/importmap
index 36502ab1..05b5f755 100755
--- a/bin/importmap
+++ b/bin/importmap
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
-require_relative "../config/application"
-require "importmap/commands"
+require_relative '../config/application'
+require 'importmap/commands'
diff --git a/config/importmap.rb b/config/importmap.rb
index 2eb08a74..0bef93f9 100644
--- a/config/importmap.rb
+++ b/config/importmap.rb
@@ -6,6 +6,7 @@ pin_all_from 'app/javascript/channels', under: 'channels'
pin 'application', preload: true
pin '@rails/actioncable', to: 'actioncable.esm.js'
+pin '@rails/activestorage', to: 'activestorage.esm.js'
pin '@hotwired/turbo-rails', to: 'turbo.min.js', preload: true
pin '@hotwired/stimulus', to: 'stimulus.min.js', preload: true
pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js', preload: true
@@ -17,10 +18,8 @@ pin 'chartkick', to: 'chartkick.js'
pin 'Chart.bundle', to: 'Chart.bundle.js'
pin 'leaflet.heat' # @0.2.0
pin 'leaflet-draw' # @1.0.4
-pin '@rails/actioncable', to: 'actioncable.esm.js'
-pin_all_from 'app/javascript/channels', under: 'channels'
pin 'notifications_channel', to: 'channels/notifications_channel.js'
pin 'points_channel', to: 'channels/points_channel.js'
pin 'imports_channel', to: 'channels/imports_channel.js'
-pin "trix"
-pin "@rails/actiontext", to: "actiontext.esm.js"
+pin 'trix'
+pin '@rails/actiontext', to: 'actiontext.esm.js'
diff --git a/db/data/20250404182629_set_active_until_for_selfhosted_users.rb b/db/data/20250404182629_set_active_until_for_selfhosted_users.rb
new file mode 100644
index 00000000..ffc410db
--- /dev/null
+++ b/db/data/20250404182629_set_active_until_for_selfhosted_users.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+class SetActiveUntilForSelfhostedUsers < ActiveRecord::Migration[8.0]
+ def up
+ return unless DawarichSettings.self_hosted?
+
+ # rubocop:disable Rails/SkipsModelValidations
+ User.where(active_until: nil).update_all(active_until: 1000.years.from_now)
+ # rubocop:enable Rails/SkipsModelValidations
+ end
+
+ def down
+ 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
diff --git a/db/data_schema.rb b/db/data_schema.rb
index c8d2c368..f977f743 100644
--- a/db/data_schema.rb
+++ b/db/data_schema.rb
@@ -1 +1 @@
-DataMigrate::Data.define(version: 20250403204658)
+DataMigrate::Data.define(version: 20_250_404_182_629)
diff --git a/db/migrate/20250404182437_add_active_until_to_users.rb b/db/migrate/20250404182437_add_active_until_to_users.rb
new file mode 100644
index 00000000..f42ca9b4
--- /dev/null
+++ b/db/migrate/20250404182437_add_active_until_to_users.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddActiveUntilToUsers < ActiveRecord::Migration[8.0]
+ def change
+ add_column :users, :active_until, :datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f6e71855..68eac3a8 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,260 +10,264 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[8.0].define(version: 2025_03_24_180755) do
+ActiveRecord::Schema[8.0].define(version: 20_250_404_182_437) do
# These are extensions that must be enabled in order to support this database
- enable_extension "pg_catalog.plpgsql"
- enable_extension "postgis"
+ enable_extension 'pg_catalog.plpgsql'
+ enable_extension 'postgis'
- create_table "action_text_rich_texts", force: :cascade do |t|
- t.string "name", null: false
- t.text "body"
- t.string "record_type", null: false
- t.bigint "record_id", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
+ create_table 'action_text_rich_texts', force: :cascade do |t|
+ t.string 'name', null: false
+ t.text 'body'
+ t.string 'record_type', null: false
+ t.bigint 'record_id', null: false
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.index %w[record_type record_id name], name: 'index_action_text_rich_texts_uniqueness', unique: true
end
- create_table "active_storage_attachments", force: :cascade do |t|
- t.string "name", null: false
- t.string "record_type", null: false
- t.bigint "record_id", null: false
- t.bigint "blob_id", null: false
- t.datetime "created_at", null: false
- t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
- t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
+ create_table 'active_storage_attachments', force: :cascade do |t|
+ t.string 'name', null: false
+ t.string 'record_type', null: false
+ t.bigint 'record_id', null: false
+ t.bigint 'blob_id', null: false
+ t.datetime 'created_at', null: false
+ t.index ['blob_id'], name: 'index_active_storage_attachments_on_blob_id'
+ t.index %w[record_type record_id name blob_id], name: 'index_active_storage_attachments_uniqueness',
+unique: true
end
- create_table "active_storage_blobs", force: :cascade do |t|
- t.string "key", null: false
- t.string "filename", null: false
- t.string "content_type"
- t.text "metadata"
- t.string "service_name", null: false
- t.bigint "byte_size", null: false
- t.string "checksum"
- t.datetime "created_at", null: false
- t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
+ create_table 'active_storage_blobs', force: :cascade do |t|
+ t.string 'key', null: false
+ t.string 'filename', null: false
+ t.string 'content_type'
+ t.text 'metadata'
+ t.string 'service_name', null: false
+ t.bigint 'byte_size', null: false
+ t.string 'checksum'
+ t.datetime 'created_at', null: false
+ t.index ['key'], name: 'index_active_storage_blobs_on_key', unique: true
end
- create_table "active_storage_variant_records", force: :cascade do |t|
- t.bigint "blob_id", null: false
- t.string "variation_digest", null: false
- t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
+ create_table 'active_storage_variant_records', force: :cascade do |t|
+ t.bigint 'blob_id', null: false
+ t.string 'variation_digest', null: false
+ t.index %w[blob_id variation_digest], name: 'index_active_storage_variant_records_uniqueness', unique: true
end
- create_table "areas", force: :cascade do |t|
- t.string "name", null: false
- t.bigint "user_id", null: false
- t.decimal "longitude", precision: 10, scale: 6, null: false
- t.decimal "latitude", precision: 10, scale: 6, null: false
- t.integer "radius", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["user_id"], name: "index_areas_on_user_id"
+ create_table 'areas', force: :cascade do |t|
+ t.string 'name', null: false
+ t.bigint 'user_id', null: false
+ t.decimal 'longitude', precision: 10, scale: 6, null: false
+ t.decimal 'latitude', precision: 10, scale: 6, null: false
+ t.integer 'radius', null: false
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.index ['user_id'], name: 'index_areas_on_user_id'
end
- create_table "data_migrations", primary_key: "version", id: :string, force: :cascade do |t|
+ create_table 'data_migrations', primary_key: 'version', id: :string, force: :cascade do |t|
end
- create_table "exports", force: :cascade do |t|
- t.string "name", null: false
- t.string "url"
- t.integer "status", default: 0, null: false
- t.bigint "user_id", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.integer "file_format", default: 0
- t.datetime "start_at"
- t.datetime "end_at"
- t.index ["status"], name: "index_exports_on_status"
- t.index ["user_id"], name: "index_exports_on_user_id"
+ create_table 'exports', force: :cascade do |t|
+ t.string 'name', null: false
+ t.string 'url'
+ t.integer 'status', default: 0, null: false
+ t.bigint 'user_id', null: false
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.integer 'file_format', default: 0
+ t.datetime 'start_at'
+ t.datetime 'end_at'
+ t.index ['status'], name: 'index_exports_on_status'
+ t.index ['user_id'], name: 'index_exports_on_user_id'
end
- create_table "imports", force: :cascade do |t|
- t.string "name", null: false
- t.bigint "user_id", null: false
- t.integer "source", default: 0
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.integer "raw_points", default: 0
- t.integer "doubles", default: 0
- t.integer "processed", default: 0
- t.jsonb "raw_data"
- t.integer "points_count", default: 0
- t.index ["source"], name: "index_imports_on_source"
- t.index ["user_id"], name: "index_imports_on_user_id"
+ create_table 'imports', force: :cascade do |t|
+ t.string 'name', null: false
+ t.bigint 'user_id', null: false
+ t.integer 'source', default: 0
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.integer 'raw_points', default: 0
+ t.integer 'doubles', default: 0
+ t.integer 'processed', default: 0
+ t.jsonb 'raw_data'
+ t.integer 'points_count', default: 0
+ t.index ['source'], name: 'index_imports_on_source'
+ t.index ['user_id'], name: 'index_imports_on_user_id'
end
- create_table "notifications", force: :cascade do |t|
- t.string "title", null: false
- t.text "content", null: false
- t.bigint "user_id", null: false
- t.integer "kind", default: 0, null: false
- t.datetime "read_at"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["kind"], name: "index_notifications_on_kind"
- t.index ["user_id"], name: "index_notifications_on_user_id"
+ create_table 'notifications', force: :cascade do |t|
+ t.string 'title', null: false
+ t.text 'content', null: false
+ t.bigint 'user_id', null: false
+ t.integer 'kind', default: 0, null: false
+ t.datetime 'read_at'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.index ['kind'], name: 'index_notifications_on_kind'
+ t.index ['user_id'], name: 'index_notifications_on_user_id'
end
- create_table "place_visits", force: :cascade do |t|
- t.bigint "place_id", null: false
- t.bigint "visit_id", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["place_id"], name: "index_place_visits_on_place_id"
- t.index ["visit_id"], name: "index_place_visits_on_visit_id"
+ create_table 'place_visits', force: :cascade do |t|
+ t.bigint 'place_id', null: false
+ t.bigint 'visit_id', null: false
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.index ['place_id'], name: 'index_place_visits_on_place_id'
+ t.index ['visit_id'], name: 'index_place_visits_on_visit_id'
end
- create_table "places", force: :cascade do |t|
- t.string "name", null: false
- t.decimal "longitude", precision: 10, scale: 6, null: false
- t.decimal "latitude", precision: 10, scale: 6, null: false
- t.string "city"
- t.string "country"
- t.integer "source", default: 0
- t.jsonb "geodata", default: {}, null: false
- t.datetime "reverse_geocoded_at"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.geography "lonlat", limit: {srid: 4326, type: "st_point", geographic: true}
- t.index ["lonlat"], name: "index_places_on_lonlat", using: :gist
+ create_table 'places', force: :cascade do |t|
+ t.string 'name', null: false
+ t.decimal 'longitude', precision: 10, scale: 6, null: false
+ t.decimal 'latitude', precision: 10, scale: 6, null: false
+ t.string 'city'
+ t.string 'country'
+ t.integer 'source', default: 0
+ t.jsonb 'geodata', default: {}, null: false
+ t.datetime 'reverse_geocoded_at'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.geography 'lonlat', limit: { srid: 4326, type: 'st_point', geographic: true }
+ t.index ['lonlat'], name: 'index_places_on_lonlat', using: :gist
end
- create_table "points", force: :cascade do |t|
- t.integer "battery_status"
- t.string "ping"
- t.integer "battery"
- t.string "tracker_id"
- t.string "topic"
- t.integer "altitude"
- t.decimal "longitude", precision: 10, scale: 6
- t.string "velocity"
- t.integer "trigger"
- t.string "bssid"
- t.string "ssid"
- t.integer "connection"
- t.integer "vertical_accuracy"
- t.integer "accuracy"
- t.integer "timestamp"
- t.decimal "latitude", precision: 10, scale: 6
- t.integer "mode"
- t.text "inrids", default: [], array: true
- t.text "in_regions", default: [], array: true
- t.jsonb "raw_data", default: {}
- t.bigint "import_id"
- t.string "city"
- t.string "country"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.bigint "user_id"
- t.jsonb "geodata", default: {}, null: false
- t.bigint "visit_id"
- t.datetime "reverse_geocoded_at"
- t.decimal "course", precision: 8, scale: 5
- t.decimal "course_accuracy", precision: 8, scale: 5
- t.string "external_track_id"
- t.geography "lonlat", limit: {srid: 4326, type: "st_point", geographic: true}
- t.index ["altitude"], name: "index_points_on_altitude"
- t.index ["battery"], name: "index_points_on_battery"
- t.index ["battery_status"], name: "index_points_on_battery_status"
- t.index ["city"], name: "index_points_on_city"
- t.index ["connection"], name: "index_points_on_connection"
- t.index ["country"], name: "index_points_on_country"
- t.index ["external_track_id"], name: "index_points_on_external_track_id"
- t.index ["geodata"], name: "index_points_on_geodata", using: :gin
- t.index ["import_id"], name: "index_points_on_import_id"
- t.index ["latitude", "longitude"], name: "index_points_on_latitude_and_longitude"
- t.index ["lonlat", "timestamp", "user_id"], name: "index_points_on_lonlat_timestamp_user_id", unique: true
- t.index ["lonlat"], name: "index_points_on_lonlat", using: :gist
- t.index ["reverse_geocoded_at"], name: "index_points_on_reverse_geocoded_at"
- t.index ["timestamp"], name: "index_points_on_timestamp"
- t.index ["trigger"], name: "index_points_on_trigger"
- t.index ["user_id"], name: "index_points_on_user_id"
- t.index ["visit_id"], name: "index_points_on_visit_id"
+ create_table 'points', force: :cascade do |t|
+ t.integer 'battery_status'
+ t.string 'ping'
+ t.integer 'battery'
+ t.string 'tracker_id'
+ t.string 'topic'
+ t.integer 'altitude'
+ t.decimal 'longitude', precision: 10, scale: 6
+ t.string 'velocity'
+ t.integer 'trigger'
+ t.string 'bssid'
+ t.string 'ssid'
+ t.integer 'connection'
+ t.integer 'vertical_accuracy'
+ t.integer 'accuracy'
+ t.integer 'timestamp'
+ t.decimal 'latitude', precision: 10, scale: 6
+ t.integer 'mode'
+ t.text 'inrids', default: [], array: true
+ t.text 'in_regions', default: [], array: true
+ t.jsonb 'raw_data', default: {}
+ t.bigint 'import_id'
+ t.string 'city'
+ t.string 'country'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.bigint 'user_id'
+ t.jsonb 'geodata', default: {}, null: false
+ t.bigint 'visit_id'
+ t.datetime 'reverse_geocoded_at'
+ t.decimal 'course', precision: 8, scale: 5
+ t.decimal 'course_accuracy', precision: 8, scale: 5
+ t.string 'external_track_id'
+ t.geography 'lonlat', limit: { srid: 4326, type: 'st_point', geographic: true }
+ t.index ['altitude'], name: 'index_points_on_altitude'
+ t.index ['battery'], name: 'index_points_on_battery'
+ t.index ['battery_status'], name: 'index_points_on_battery_status'
+ t.index ['city'], name: 'index_points_on_city'
+ t.index ['connection'], name: 'index_points_on_connection'
+ t.index ['country'], name: 'index_points_on_country'
+ t.index ['external_track_id'], name: 'index_points_on_external_track_id'
+ t.index ['geodata'], name: 'index_points_on_geodata', using: :gin
+ t.index ['import_id'], name: 'index_points_on_import_id'
+ t.index %w[latitude longitude], name: 'index_points_on_latitude_and_longitude'
+ t.index %w[lonlat timestamp user_id], name: 'index_points_on_lonlat_timestamp_user_id', unique: true
+ t.index ['lonlat'], name: 'index_points_on_lonlat', using: :gist
+ t.index ['reverse_geocoded_at'], name: 'index_points_on_reverse_geocoded_at'
+ t.index ['timestamp'], name: 'index_points_on_timestamp'
+ t.index ['trigger'], name: 'index_points_on_trigger'
+ t.index ['user_id'], name: 'index_points_on_user_id'
+ t.index ['visit_id'], name: 'index_points_on_visit_id'
end
- create_table "stats", force: :cascade do |t|
- t.integer "year", null: false
- t.integer "month", null: false
- t.integer "distance", null: false
- t.jsonb "toponyms"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.bigint "user_id", null: false
- t.jsonb "daily_distance", default: {}
- t.index ["distance"], name: "index_stats_on_distance"
- t.index ["month"], name: "index_stats_on_month"
- t.index ["user_id"], name: "index_stats_on_user_id"
- t.index ["year"], name: "index_stats_on_year"
+ create_table 'stats', force: :cascade do |t|
+ t.integer 'year', null: false
+ t.integer 'month', null: false
+ t.integer 'distance', null: false
+ t.jsonb 'toponyms'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.bigint 'user_id', null: false
+ t.jsonb 'daily_distance', default: {}
+ t.index ['distance'], name: 'index_stats_on_distance'
+ t.index ['month'], name: 'index_stats_on_month'
+ t.index ['user_id'], name: 'index_stats_on_user_id'
+ t.index ['year'], name: 'index_stats_on_year'
end
- create_table "trips", force: :cascade do |t|
- t.string "name", null: false
- t.datetime "started_at", null: false
- t.datetime "ended_at", null: false
- t.integer "distance"
- t.bigint "user_id", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.geometry "path", limit: {srid: 3857, type: "line_string"}
- t.index ["user_id"], name: "index_trips_on_user_id"
+ create_table 'trips', force: :cascade do |t|
+ t.string 'name', null: false
+ t.datetime 'started_at', null: false
+ t.datetime 'ended_at', null: false
+ t.integer 'distance'
+ t.bigint 'user_id', null: false
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.geometry 'path', limit: { srid: 3857, type: 'line_string' }
+ t.index ['user_id'], name: 'index_trips_on_user_id'
end
- create_table "users", force: :cascade do |t|
- t.string "email", default: "", null: false
- t.string "encrypted_password", default: "", null: false
- t.string "reset_password_token"
- t.datetime "reset_password_sent_at"
- t.datetime "remember_created_at"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "api_key", default: "", null: false
- t.string "theme", default: "dark", null: false
- t.jsonb "settings", default: {"fog_of_war_meters" => "100", "meters_between_routes" => "1000", "minutes_between_routes" => "60"}
- t.boolean "admin", default: false
- t.integer "sign_in_count", default: 0, null: false
- t.datetime "current_sign_in_at"
- t.datetime "last_sign_in_at"
- t.string "current_sign_in_ip"
- t.string "last_sign_in_ip"
- t.integer "status", default: 0
- t.index ["email"], name: "index_users_on_email", unique: true
- t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
+ create_table 'users', force: :cascade do |t|
+ t.string 'email', default: '', null: false
+ t.string 'encrypted_password', default: '', null: false
+ t.string 'reset_password_token'
+ t.datetime 'reset_password_sent_at'
+ t.datetime 'remember_created_at'
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.string 'api_key', default: '', null: false
+ t.string 'theme', default: 'dark', null: false
+ t.jsonb 'settings',
+ default: { 'fog_of_war_meters' => '100', 'meters_between_routes' => '1000',
+'minutes_between_routes' => '60' }
+ t.boolean 'admin', default: false
+ t.integer 'sign_in_count', default: 0, null: false
+ t.datetime 'current_sign_in_at'
+ t.datetime 'last_sign_in_at'
+ t.string 'current_sign_in_ip'
+ t.string 'last_sign_in_ip'
+ t.integer 'status', default: 0
+ t.datetime 'active_until'
+ t.index ['email'], name: 'index_users_on_email', unique: true
+ t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
end
- add_check_constraint "users", "admin IS NOT NULL", name: "users_admin_null", validate: false
+ add_check_constraint 'users', 'admin IS NOT NULL', name: 'users_admin_null', validate: false
- create_table "visits", force: :cascade do |t|
- t.bigint "area_id"
- t.bigint "user_id", null: false
- t.datetime "started_at", null: false
- t.datetime "ended_at", null: false
- t.integer "duration", null: false
- t.string "name", null: false
- t.integer "status", default: 0, null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.bigint "place_id"
- t.index ["area_id"], name: "index_visits_on_area_id"
- t.index ["place_id"], name: "index_visits_on_place_id"
- t.index ["started_at"], name: "index_visits_on_started_at"
- t.index ["user_id"], name: "index_visits_on_user_id"
+ create_table 'visits', force: :cascade do |t|
+ t.bigint 'area_id'
+ t.bigint 'user_id', null: false
+ t.datetime 'started_at', null: false
+ t.datetime 'ended_at', null: false
+ t.integer 'duration', null: false
+ t.string 'name', null: false
+ t.integer 'status', default: 0, null: false
+ t.datetime 'created_at', null: false
+ t.datetime 'updated_at', null: false
+ t.bigint 'place_id'
+ t.index ['area_id'], name: 'index_visits_on_area_id'
+ t.index ['place_id'], name: 'index_visits_on_place_id'
+ t.index ['started_at'], name: 'index_visits_on_started_at'
+ t.index ['user_id'], name: 'index_visits_on_user_id'
end
- add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
- add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
- add_foreign_key "areas", "users"
- add_foreign_key "notifications", "users"
- add_foreign_key "place_visits", "places"
- add_foreign_key "place_visits", "visits"
- add_foreign_key "points", "users"
- add_foreign_key "points", "visits"
- add_foreign_key "stats", "users"
- add_foreign_key "trips", "users"
- add_foreign_key "visits", "areas"
- add_foreign_key "visits", "places"
- add_foreign_key "visits", "users"
+ add_foreign_key 'active_storage_attachments', 'active_storage_blobs', column: 'blob_id'
+ add_foreign_key 'active_storage_variant_records', 'active_storage_blobs', column: 'blob_id'
+ add_foreign_key 'areas', 'users'
+ add_foreign_key 'notifications', 'users'
+ add_foreign_key 'place_visits', 'places'
+ add_foreign_key 'place_visits', 'visits'
+ add_foreign_key 'points', 'users'
+ add_foreign_key 'points', 'visits'
+ add_foreign_key 'stats', 'users'
+ add_foreign_key 'trips', 'users'
+ add_foreign_key 'visits', 'areas'
+ add_foreign_key 'visits', 'places'
+ add_foreign_key 'visits', 'users'
end
diff --git a/spec/factories/users.rb b/spec/factories/users.rb
index 1f1c54bc..2b6c8c17 100644
--- a/spec/factories/users.rb
+++ b/spec/factories/users.rb
@@ -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
{
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index a3a1e3e8..babd2fa8 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -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
diff --git a/spec/requests/api/v1/overland/batches_spec.rb b/spec/requests/api/v1/overland/batches_spec.rb
index a673480b..df5f74e0 100644
--- a/spec/requests/api/v1/overland/batches_spec.rb
+++ b/spec/requests/api/v1/overland/batches_spec.rb
@@ -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
diff --git a/spec/requests/api/v1/owntracks/points_spec.rb b/spec/requests/api/v1/owntracks/points_spec.rb
index 39cf486f..f8e6128e 100644
--- a/spec/requests/api/v1/owntracks/points_spec.rb
+++ b/spec/requests/api/v1/owntracks/points_spec.rb
@@ -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
diff --git a/spec/requests/api/v1/points_spec.rb b/spec/requests/api/v1/points_spec.rb
index f218d085..1983640c 100644
--- a/spec/requests/api/v1/points_spec.rb
+++ b/spec/requests/api/v1/points_spec.rb
@@ -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
diff --git a/spec/requests/api/v1/settings_spec.rb b/spec/requests/api/v1/settings_spec.rb
index 075e3dca..3f6673e5 100644
--- a/spec/requests/api/v1/settings_spec.rb
+++ b/spec/requests/api/v1/settings_spec.rb
@@ -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
diff --git a/spec/requests/settings_spec.rb b/spec/requests/settings_spec.rb
index f457855c..a06d0b40 100644
--- a/spec/requests/settings_spec.rb
+++ b/spec/requests/settings_spec.rb
@@ -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
diff --git a/spec/requests/stats_spec.rb b/spec/requests/stats_spec.rb
index 516f4cd3..b6755cb9 100644
--- a/spec/requests/stats_spec.rb
+++ b/spec/requests/stats_spec.rb
@@ -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
diff --git a/spec/requests/trips_spec.rb b/spec/requests/trips_spec.rb
index 3f536edc..af654048 100644
--- a/spec/requests/trips_spec.rb
+++ b/spec/requests/trips_spec.rb
@@ -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