mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-13 02:31:39 -05:00
Merge pull request #944 from Freika/feature/sample-points
Feature/sample points
This commit is contained in:
commit
d6ba3dfec8
4 changed files with 2629 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ This release is focused on improving the visits experience.
|
|||
- User can now select two or more visits in the visits drawer and merge them into a single visit. This operation is not reversible.
|
||||
- User can now select two or more visits in the visits drawer and confirm or decline them at once. This operation is not reversible.
|
||||
- Status field to the User model. Inactive users are now being restricted from accessing some of the functionality, which is mostly about writing data to the database. Reading is remaining unrestricted.
|
||||
- After user is created, a sample import is being created for them to demonstrate how to use the app.
|
||||
|
||||
|
||||
## Changed
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class User < ApplicationRecord
|
|||
has_many :trips, dependent: :destroy
|
||||
|
||||
after_create :create_api_key
|
||||
after_create :import_sample_points
|
||||
after_commit :activate, on: :create, if: -> { DawarichSettings.self_hosted? }
|
||||
before_save :sanitize_input
|
||||
|
||||
|
|
@ -116,4 +117,22 @@ class User < ApplicationRecord
|
|||
settings['photoprism_url']&.gsub!(%r{/+\z}, '')
|
||||
settings.try(:[], 'maps')&.try(:[], 'url')&.strip!
|
||||
end
|
||||
|
||||
def import_sample_points
|
||||
return unless Rails.env.development? ||
|
||||
Rails.env.production? ||
|
||||
(Rails.env.test? && ENV['IMPORT_SAMPLE_POINTS'])
|
||||
|
||||
raw_data = Hash.from_xml(
|
||||
File.read(Rails.root.join('lib/assets/sample_points.gpx'))
|
||||
)
|
||||
|
||||
import = imports.create(
|
||||
name: 'DELETE_ME_this_is_a_demo_import_DELETE_ME',
|
||||
source: 'gpx',
|
||||
raw_data:
|
||||
)
|
||||
|
||||
ImportJob.perform_later(id, import.id)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
2589
lib/assets/sample_points.gpx
Normal file
2589
lib/assets/sample_points.gpx
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -55,6 +55,26 @@ RSpec.describe User, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#import_sample_points' do
|
||||
before do
|
||||
ENV['IMPORT_SAMPLE_POINTS'] = 'true'
|
||||
end
|
||||
|
||||
after do
|
||||
ENV['IMPORT_SAMPLE_POINTS'] = nil
|
||||
end
|
||||
|
||||
it 'creates a sample import and enqueues an import job' do
|
||||
user = create(:user)
|
||||
|
||||
expect(user.imports.count).to eq(1)
|
||||
expect(user.imports.first.name).to eq('DELETE_ME_this_is_a_demo_import_DELETE_ME')
|
||||
expect(user.imports.first.source).to eq('gpx')
|
||||
|
||||
expect(ImportJob).to have_been_enqueued.with(user.id, user.imports.first.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'methods' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue