forked from fixin.me/fixin.me
Compare commits
1 Commits
pr68-setup
...
fix-sqlite
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e1699a4b5 |
@@ -9,7 +9,6 @@ class ApplicationController < ActionController::Base
|
|||||||
helper_method :current_user_disguised?
|
helper_method :current_user_disguised?
|
||||||
helper_method :current_tab
|
helper_method :current_tab
|
||||||
|
|
||||||
before_action :redirect_to_setup_if_needed
|
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
class AccessForbidden < StandardError; end
|
class AccessForbidden < StandardError; end
|
||||||
@@ -56,16 +55,6 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Redirect to the web setup wizard when the application has not yet been
|
|
||||||
# initialised (i.e. no admin account exists in the database).
|
|
||||||
def redirect_to_setup_if_needed
|
|
||||||
return if User.exists?(status: :admin)
|
|
||||||
redirect_to new_setup_path
|
|
||||||
rescue ActiveRecord::StatementInvalid
|
|
||||||
# Tables may not exist yet (migrations not run). Fall through and let the
|
|
||||||
# normal request handling surface a meaningful error.
|
|
||||||
end
|
|
||||||
|
|
||||||
def render_no_content(record)
|
def render_no_content(record)
|
||||||
helpers.render_errors(record)
|
helpers.render_errors(record)
|
||||||
render html: nil, layout: true
|
render html: nil, layout: true
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
# Handles the one-time web-based installation wizard.
|
|
||||||
#
|
|
||||||
# The wizard is only accessible when no admin account exists yet. Once an
|
|
||||||
# admin has been created the controller redirects every request to the root
|
|
||||||
# path, so it can never be used to overwrite an existing installation.
|
|
||||||
class SetupController < ActionController::Base
|
|
||||||
# Use the full application layout (header, flash, etc.) so the page looks
|
|
||||||
# consistent with the rest of the site.
|
|
||||||
layout "application"
|
|
||||||
|
|
||||||
before_action :redirect_if_installed
|
|
||||||
|
|
||||||
def new
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
email = params[:admin_email].to_s.strip
|
|
||||||
password = params[:admin_password].to_s
|
|
||||||
confirm = params[:admin_password_confirmation].to_s
|
|
||||||
|
|
||||||
errors = []
|
|
||||||
errors << t(".email_blank") if email.blank?
|
|
||||||
errors << t(".password_blank") if password.blank?
|
|
||||||
errors << t(".password_mismatch") if password != confirm
|
|
||||||
|
|
||||||
if errors.any?
|
|
||||||
flash.now[:alert] = errors.join(" ")
|
|
||||||
return render :new, status: :unprocessable_entity
|
|
||||||
end
|
|
||||||
|
|
||||||
user = User.new(email: email, password: password, status: :admin)
|
|
||||||
user.skip_confirmation!
|
|
||||||
|
|
||||||
unless user.save
|
|
||||||
flash.now[:alert] = user.errors.full_messages.join(" ")
|
|
||||||
return render :new, status: :unprocessable_entity
|
|
||||||
end
|
|
||||||
|
|
||||||
# Persist runtime settings chosen during setup.
|
|
||||||
Setting.set("skip_email_confirmation",
|
|
||||||
params[:skip_email_confirmation] == "1")
|
|
||||||
|
|
||||||
# Optionally seed the built-in default units.
|
|
||||||
if params[:seed_units] == "1"
|
|
||||||
load Rails.root.join("db/seeds/units.rb")
|
|
||||||
end
|
|
||||||
|
|
||||||
redirect_to new_user_session_path, notice: t(".success")
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def redirect_if_installed
|
|
||||||
redirect_to root_path if User.exists?(status: :admin)
|
|
||||||
rescue ActiveRecord::StatementInvalid
|
|
||||||
# Tables are not yet migrated — stay on the setup page so the user sees a
|
|
||||||
# meaningful error rather than a crash.
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -6,15 +6,6 @@ class User::ProfilesController < Devise::RegistrationsController
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def build_resource(hash = {})
|
|
||||||
super
|
|
||||||
# Skip the email confirmation step when the admin has enabled this option
|
|
||||||
# via the web setup wizard (stored as the "skip_email_confirmation" Setting).
|
|
||||||
# The account becomes active immediately so the user can sign in right after
|
|
||||||
# registering.
|
|
||||||
resource.skip_confirmation! if Setting.get("skip_email_confirmation") == "true"
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_resource(resource, params)
|
def update_resource(resource, params)
|
||||||
# Based on update_with_password()
|
# Based on update_with_password()
|
||||||
if params[:password].blank?
|
if params[:password].blank?
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ class Quantity < ApplicationRecord
|
|||||||
errors.add(:parent, :descendant_reference) if ancestor_of?(parent)
|
errors.add(:parent, :descendant_reference) if ancestor_of?(parent)
|
||||||
end
|
end
|
||||||
validates :name, presence: true, uniqueness: {scope: [:user_id, :parent_id]},
|
validates :name, presence: true, uniqueness: {scope: [:user_id, :parent_id]},
|
||||||
length: {maximum: type_for_attribute(:name).limit || Float::INFINITY}
|
length: {maximum: type_for_attribute(:name).limit}
|
||||||
validates :description, length: {maximum: type_for_attribute(:description).limit || Float::INFINITY}
|
validates :description, length: {maximum: type_for_attribute(:description).limit} if type_for_attribute(:description).limit
|
||||||
|
|
||||||
# Update :depths of progenies after parent change
|
# Update :depths of progenies after parent change
|
||||||
before_save if: :parent_changed? do
|
before_save if: :parent_changed? do
|
||||||
@@ -61,18 +61,22 @@ class Quantity < ApplicationRecord
|
|||||||
|
|
||||||
# Return: ordered [sub]hierarchy
|
# Return: ordered [sub]hierarchy
|
||||||
scope :ordered, ->(root: nil, include_root: true) {
|
scope :ordered, ->(root: nil, include_root: true) {
|
||||||
numbered = Arel::Table.new('numbered')
|
q_ordered = Arel::Table.new('q_ordered')
|
||||||
|
cast_type = connection.adapter_name == 'Mysql2' ? 'BINARY' : 'BLOB'
|
||||||
|
|
||||||
self.model.with(numbered: numbered(:parent_id, :name)).with_recursive(arel_table.name => [
|
self.model.with(numbered: numbered(:parent_id, :name)).with_recursive(q_ordered: [
|
||||||
numbered.project(
|
Quantity.from(Arel::Table.new('numbered').as(arel_table.name))
|
||||||
numbered[Arel.star],
|
.select(
|
||||||
numbered.cast(numbered[:child_number], 'BINARY').as('path')
|
arel_table[Arel.star],
|
||||||
).where(numbered[root && include_root ? :id : :parent_id].eq(root)),
|
arel_table.cast(arel_table[:child_number], cast_type).as('path')
|
||||||
numbered.project(
|
).where(arel_table[root && include_root ? :id : :parent_id].eq(root)),
|
||||||
numbered[Arel.star],
|
Quantity.from(Arel::Table.new('numbered').as(arel_table.name))
|
||||||
arel_table[:path].concat(numbered[:child_number])
|
.joins("INNER JOIN q_ordered ON quantities.parent_id = q_ordered.id")
|
||||||
).join(arel_table).on(numbered[:parent_id].eq(arel_table[:id]))
|
.select(
|
||||||
]).order(arel_table[:path])
|
arel_table[Arel.star],
|
||||||
|
q_ordered[:path].concat(arel_table[:child_number])
|
||||||
|
)
|
||||||
|
]).from(q_ordered.as(arel_table.name)).order(arel_table[:path])
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: extract named functions to custom Arel extension
|
# TODO: extract named functions to custom Arel extension
|
||||||
@@ -80,20 +84,24 @@ class Quantity < ApplicationRecord
|
|||||||
# be merged with :ordered
|
# be merged with :ordered
|
||||||
# https://gist.github.com/ProGM/c6df08da14708dcc28b5ca325df37ceb#extending-arel
|
# https://gist.github.com/ProGM/c6df08da14708dcc28b5ca325df37ceb#extending-arel
|
||||||
scope :numbered, ->(parent_column, order_column) {
|
scope :numbered, ->(parent_column, order_column) {
|
||||||
select(
|
row_number = Arel::Nodes::NamedFunction.new('ROW_NUMBER', [])
|
||||||
arel_table[Arel.star],
|
.over(Arel::Nodes::Window.new.partition(parent_column).order(order_column))
|
||||||
Arel::Nodes::NamedFunction.new(
|
width = Arel::SelectManager.new.project(
|
||||||
'LPAD',
|
Arel::Nodes::NamedFunction.new('LENGTH', [Arel.star.count])
|
||||||
[
|
).from(arel_table)
|
||||||
Arel::Nodes::NamedFunction.new('ROW_NUMBER', [])
|
|
||||||
.over(Arel::Nodes::Window.new.partition(parent_column).order(order_column)),
|
pad_expr = if connection.adapter_name == 'Mysql2'
|
||||||
Arel::SelectManager.new.project(
|
Arel::Nodes::NamedFunction.new('LPAD', [row_number, width, Arel::Nodes.build_quoted('0')])
|
||||||
Arel::Nodes::NamedFunction.new('LENGTH', [Arel.star.count])
|
else
|
||||||
).from(arel_table),
|
# SQLite: printf('%0' || width || 'd', row_number)
|
||||||
Arel::Nodes.build_quoted('0')
|
fmt = Arel::Nodes::InfixOperation.new('||',
|
||||||
],
|
Arel::Nodes::InfixOperation.new('||', Arel::Nodes.build_quoted('%0'), width),
|
||||||
).as('child_number')
|
Arel::Nodes.build_quoted('d')
|
||||||
)
|
)
|
||||||
|
Arel::Nodes::NamedFunction.new('printf', [fmt, row_number])
|
||||||
|
end
|
||||||
|
|
||||||
|
select(arel_table[Arel.star], pad_expr.as('child_number'))
|
||||||
}
|
}
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@@ -102,7 +110,7 @@ class Quantity < ApplicationRecord
|
|||||||
|
|
||||||
def to_s_with_depth
|
def to_s_with_depth
|
||||||
# em space, U+2003
|
# em space, U+2003
|
||||||
' ' * depth + name
|
' ' * depth + name
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroyable?
|
def destroyable?
|
||||||
@@ -115,16 +123,18 @@ class Quantity < ApplicationRecord
|
|||||||
|
|
||||||
# Common ancestors, assuming node is a descendant of itself
|
# Common ancestors, assuming node is a descendant of itself
|
||||||
scope :common_ancestors, ->(of) {
|
scope :common_ancestors, ->(of) {
|
||||||
selected = Arel::Table.new('selected')
|
q_common = Arel::Table.new('q_common')
|
||||||
|
|
||||||
# Take unique IDs, so self can be called with parent nodes of collection to
|
# Take unique IDs, so self can be called with parent nodes of collection to
|
||||||
# get common ancestors of collection _excluding_ nodes in collection.
|
# get common ancestors of collection _excluding_ nodes in collection.
|
||||||
uniq_of = of.uniq
|
uniq_of = of.uniq
|
||||||
model.with(selected: self).with_recursive(arel_table.name => [
|
model.with(selected: self).with_recursive(q_common: [
|
||||||
selected.project(selected[Arel.star]).where(selected[:id].in(uniq_of)),
|
Quantity.from(Arel::Table.new('selected').as(arel_table.name))
|
||||||
selected.project(selected[Arel.star])
|
.where(arel_table[:id].in(uniq_of)),
|
||||||
.join(arel_table).on(selected[:id].eq(arel_table[:parent_id]))
|
Quantity.from(Arel::Table.new('selected').as(arel_table.name))
|
||||||
|
.joins("INNER JOIN q_common ON selected.id = q_common.parent_id")
|
||||||
]).select(arel_table[Arel.star])
|
]).select(arel_table[Arel.star])
|
||||||
|
.from(q_common.as(arel_table.name))
|
||||||
.group(column_names)
|
.group(column_names)
|
||||||
.having(arel_table[:id].count.eq(uniq_of.size))
|
.having(arel_table[:id].count.eq(uniq_of.size))
|
||||||
.order(arel_table[:depth].desc)
|
.order(arel_table[:depth].desc)
|
||||||
@@ -132,13 +142,9 @@ class Quantity < ApplicationRecord
|
|||||||
|
|
||||||
# Return: successive record in order of appearance; used for partial view reload
|
# Return: successive record in order of appearance; used for partial view reload
|
||||||
def successive
|
def successive
|
||||||
quantities = Quantity.arel_table
|
ordered = user.quantities.ordered.to_a
|
||||||
Quantity.with(
|
idx = ordered.index { |q| q.id == id }
|
||||||
quantities: user.quantities.ordered.select(
|
ordered[idx + 1] if idx
|
||||||
quantities[Arel.star],
|
|
||||||
Arel::Nodes::NamedFunction.new('LAG', [quantities[:id]]).over.as('lag_id')
|
|
||||||
)
|
|
||||||
).where(quantities[:lag_id].eq(id)).first
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_progenies
|
def with_progenies
|
||||||
@@ -151,13 +157,14 @@ class Quantity < ApplicationRecord
|
|||||||
|
|
||||||
# Return: record with ID `of` with its ancestors, sorted by :depth
|
# Return: record with ID `of` with its ancestors, sorted by :depth
|
||||||
scope :with_ancestors, ->(of) {
|
scope :with_ancestors, ->(of) {
|
||||||
selected = Arel::Table.new('selected')
|
q_ancestors = Arel::Table.new('q_ancestors')
|
||||||
|
|
||||||
model.with(selected: self).with_recursive(arel_table.name => [
|
model.with(selected: self).with_recursive(q_ancestors: [
|
||||||
selected.project(selected[Arel.star]).where(selected[:id].eq(of)),
|
Quantity.from(Arel::Table.new('selected').as(arel_table.name))
|
||||||
selected.project(selected[Arel.star])
|
.where(arel_table[:id].eq(of)),
|
||||||
.join(arel_table).on(selected[:id].eq(arel_table[:parent_id]))
|
Quantity.from(Arel::Table.new('selected').as(arel_table.name))
|
||||||
])
|
.joins("INNER JOIN q_ancestors ON selected.id = q_ancestors.parent_id")
|
||||||
|
]).from(q_ancestors.as(arel_table.name))
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return: ancestors of (possibly destroyed) self
|
# Return: ancestors of (possibly destroyed) self
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
# Key-value store for runtime application settings that are configured through
|
|
||||||
# the web setup wizard (or updated by an administrator) rather than hard-coded
|
|
||||||
# in application.rb.
|
|
||||||
#
|
|
||||||
# Known keys:
|
|
||||||
# skip_email_confirmation – "true"/"false", mirrors the homonymous option
|
|
||||||
# that was previously in application.rb.
|
|
||||||
class Setting < ApplicationRecord
|
|
||||||
validates :key, presence: true, uniqueness: true
|
|
||||||
|
|
||||||
# Return the string value stored for +key+, or +default+ when absent.
|
|
||||||
def self.get(key, default: nil)
|
|
||||||
find_by(key: key)&.value || default
|
|
||||||
end
|
|
||||||
|
|
||||||
# Persist +value+ for +key+, creating the record if it does not yet exist.
|
|
||||||
def self.set(key, value)
|
|
||||||
find_or_initialize_by(key: key).update!(value: value.to_s)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -12,8 +12,8 @@ class Unit < ApplicationRecord
|
|||||||
errors.add(:base, :multilevel_nesting) if base.base_id?
|
errors.add(:base, :multilevel_nesting) if base.base_id?
|
||||||
end
|
end
|
||||||
validates :symbol, presence: true, uniqueness: {scope: :user_id},
|
validates :symbol, presence: true, uniqueness: {scope: :user_id},
|
||||||
length: {maximum: type_for_attribute(:symbol).limit || Float::INFINITY}
|
length: {maximum: type_for_attribute(:symbol).limit}
|
||||||
validates :description, length: {maximum: type_for_attribute(:description).limit || Float::INFINITY}
|
validates :description, length: {maximum: type_for_attribute(:description).limit} if type_for_attribute(:description).limit
|
||||||
validates :multiplier, numericality: {equal_to: 1}, unless: :base
|
validates :multiplier, numericality: {equal_to: 1}, unless: :base
|
||||||
validates :multiplier, numericality: {greater_than: 0, precision: true, scale: true}, if: :base
|
validates :multiplier, numericality: {greater_than: 0, precision: true, scale: true}, if: :base
|
||||||
|
|
||||||
@@ -22,59 +22,72 @@ class Unit < ApplicationRecord
|
|||||||
actionable_units = Arel::Table.new('actionable_units')
|
actionable_units = Arel::Table.new('actionable_units')
|
||||||
units = actionable_units.alias('units')
|
units = actionable_units.alias('units')
|
||||||
bases_units = arel_table.alias('bases_units')
|
bases_units = arel_table.alias('bases_units')
|
||||||
other_units = arel_table.alias('other_units')
|
# Use 'all_units' alias for correlated subqueries to reference the all_units CTE.
|
||||||
other_bases_units = arel_table.alias('other_bases_units')
|
# Cannot use arel_table.alias here because the CTE is named 'all_units', not 'units'.
|
||||||
|
other_units = Arel::Table.new('all_units').alias('other_units')
|
||||||
|
other_bases_units = Arel::Table.new('all_units').alias('other_bases_units')
|
||||||
sub_units = arel_table.alias('sub_units')
|
sub_units = arel_table.alias('sub_units')
|
||||||
|
|
||||||
# TODO: move inner 'with' CTE to outer 'with recursive' - it can have multiple
|
Unit.with_recursive(
|
||||||
# CTEs, even non recursive ones.
|
# Renamed from 'units' to 'all_units' to avoid SQLite circular reference:
|
||||||
Unit.with_recursive(actionable_units: [
|
# SQLite treats any CTE in WITH RECURSIVE that references a table with the same
|
||||||
Unit.with(units: self.or(Unit.defaults)).left_joins(:base)
|
# name as the CTE itself as a circular reference, even for non-recursive CTEs.
|
||||||
.where.not(
|
all_units: self.or(Unit.defaults),
|
||||||
# Exclude Units that are/have default counterpart
|
actionable_units: [
|
||||||
Arel::SelectManager.new.project(1).from(other_units)
|
# Read from all_units CTE (user+defaults) aliased as the units table name.
|
||||||
.outer_join(other_bases_units)
|
# Using AR::Relation (not Arel::SelectManager) to avoid extra parentheses
|
||||||
.on(other_units[:base_id].eq(other_bases_units[:id]))
|
# around the UNION part (visit_Arel_SelectManager always wraps in parens).
|
||||||
.where(
|
Unit.from(Arel::Table.new('all_units').as(arel_table.name))
|
||||||
other_bases_units[:symbol].is_not_distinct_from(bases_units[:symbol])
|
.joins("LEFT OUTER JOIN all_units bases_units ON bases_units.id = units.base_id")
|
||||||
.and(other_units[:symbol].eq(arel_table[:symbol]))
|
.where.not(
|
||||||
.and(other_units[:user_id].is_distinct_from(arel_table[:user_id]))
|
# Exclude Units that are/have default counterpart
|
||||||
).exists
|
Arel::SelectManager.new.project(1).from(other_units)
|
||||||
)
|
.outer_join(other_bases_units)
|
||||||
.select(
|
.on(other_units[:base_id].eq(other_bases_units[:id]))
|
||||||
arel_table[Arel.star],
|
.where(
|
||||||
# Decide if Unit can be im-/exported based on existing hierarchy:
|
other_bases_units[:symbol].is_not_distinct_from(bases_units[:symbol])
|
||||||
# * same base unit symbol has to exist
|
.and(other_units[:symbol].eq(arel_table[:symbol]))
|
||||||
# * unit with subunits can only be ported to root
|
.and(other_units[:user_id].is_distinct_from(arel_table[:user_id]))
|
||||||
arel_table[:base_id].eq(nil).or(
|
).exists
|
||||||
(
|
)
|
||||||
Arel::SelectManager.new.project(1).from(other_units)
|
.select(
|
||||||
.join(sub_units).on(other_units[:id].eq(sub_units[:base_id]))
|
arel_table[Arel.star],
|
||||||
.where(
|
# Decide if Unit can be im-/exported based on existing hierarchy:
|
||||||
other_units[:symbol].eq(arel_table[:symbol])
|
# * same base unit symbol has to exist
|
||||||
.and(other_units[:user_id].is_distinct_from(arel_table[:user_id]))
|
# * unit with subunits can only be ported to root
|
||||||
).exists.not
|
arel_table[:base_id].eq(nil).or(
|
||||||
).and(
|
(
|
||||||
Arel::SelectManager.new.project(1).from(other_bases_units)
|
Arel::SelectManager.new.project(1).from(other_units)
|
||||||
.where(
|
.join(sub_units).on(other_units[:id].eq(sub_units[:base_id]))
|
||||||
other_bases_units[:symbol].is_not_distinct_from(bases_units[:symbol])
|
.where(
|
||||||
.and(other_bases_units[:user_id].is_distinct_from(bases_units[:user_id]))
|
other_units[:symbol].eq(arel_table[:symbol])
|
||||||
).exists
|
.and(other_units[:user_id].is_distinct_from(arel_table[:user_id]))
|
||||||
)
|
).exists.not
|
||||||
).as('portable')
|
).and(
|
||||||
),
|
Arel::SelectManager.new.project(1).from(other_bases_units)
|
||||||
# Fill base Units to display proper hierarchy. Duplicates will be removed
|
.where(
|
||||||
# by final group() - can't be deduplicated with UNION due to 'portable' field.
|
other_bases_units[:symbol].is_not_distinct_from(bases_units[:symbol])
|
||||||
arel_table.join(actionable_units).on(actionable_units[:base_id].eq(arel_table[:id]))
|
.and(other_bases_units[:user_id].is_distinct_from(bases_units[:user_id]))
|
||||||
.project(arel_table[Arel.star], Arel::Nodes.build_quoted(nil).as('portable'))
|
).exists
|
||||||
]).select(units: [:base_id, :symbol])
|
)
|
||||||
|
).as('portable')
|
||||||
|
),
|
||||||
|
# Fill base Units to display proper hierarchy. Duplicates will be removed
|
||||||
|
# by final group() - can't be deduplicated with UNION due to 'portable' field.
|
||||||
|
# Using AR::Relation instead of Arel::SelectManager to avoid extra parentheses
|
||||||
|
# around the UNION part (visit_Arel_SelectManager always wraps in parens).
|
||||||
|
Unit.from(Arel::Table.new('all_units').as(arel_table.name))
|
||||||
|
.joins("INNER JOIN actionable_units ON actionable_units.base_id = units.id")
|
||||||
|
.select(arel_table[Arel.star], Arel::Nodes.build_quoted(nil).as('portable'))
|
||||||
|
]
|
||||||
|
).select(units: [:base_id, :symbol])
|
||||||
.select(
|
.select(
|
||||||
units[:id].minimum.as('id'), # can be ANY_VALUE()
|
units[:id].minimum.as('id'), # can be ANY_VALUE()
|
||||||
units[:user_id].minimum.as('user_id'), # prefer non-default
|
units[:user_id].minimum.as('user_id'), # prefer non-default
|
||||||
Arel::Nodes.build_quoted(1).as('multiplier'), # disregard multiplier when sorting
|
Arel::Nodes.build_quoted(1).as('multiplier'), # disregard multiplier when sorting
|
||||||
units[:portable].minimum.as('portable')
|
units[:portable].minimum.as('portable')
|
||||||
)
|
)
|
||||||
.from(units).group(:base_id, :symbol)
|
.from(units).group(units[:base_id], units[:symbol])
|
||||||
}
|
}
|
||||||
scope :ordered, ->{
|
scope :ordered, ->{
|
||||||
left_outer_joins(:base).order(ordering)
|
left_outer_joins(:base).order(ordering)
|
||||||
@@ -84,7 +97,7 @@ class Unit < ApplicationRecord
|
|||||||
[arel_table.coalesce(Arel::Table.new(:bases_units)[:symbol], arel_table[:symbol]),
|
[arel_table.coalesce(Arel::Table.new(:bases_units)[:symbol], arel_table[:symbol]),
|
||||||
arel_table[:base_id].not_eq(nil),
|
arel_table[:base_id].not_eq(nil),
|
||||||
:multiplier,
|
:multiplier,
|
||||||
:symbol]
|
arel_table[:symbol]]
|
||||||
end
|
end
|
||||||
|
|
||||||
before_destroy do
|
before_destroy do
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
<%= form_with url: setup_path, method: :post, class: "labeled-form main-area" do %>
|
|
||||||
|
|
||||||
<h3 style="grid-column: 1 / -1; text-align: left; margin: 0;">
|
|
||||||
<%= t(".admin_account") %>
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<label for="admin_email"><%= t(".admin_email") %></label>
|
|
||||||
<%= email_field_tag :admin_email, params[:admin_email],
|
|
||||||
id: "admin_email", required: true, size: 30, autofocus: true,
|
|
||||||
autocomplete: "email" %>
|
|
||||||
|
|
||||||
<label for="admin_password"><%= t(".admin_password") %></label>
|
|
||||||
<%= password_field_tag :admin_password, nil,
|
|
||||||
id: "admin_password", required: true, size: 30,
|
|
||||||
autocomplete: "new-password" %>
|
|
||||||
|
|
||||||
<label for="admin_password_confirmation"><%= t(".admin_password_confirmation") %></label>
|
|
||||||
<%= password_field_tag :admin_password_confirmation, nil,
|
|
||||||
id: "admin_password_confirmation", required: true, size: 30,
|
|
||||||
autocomplete: "off" %>
|
|
||||||
|
|
||||||
<h3 style="grid-column: 1 / -1; text-align: left; margin: 0.5em 0 0 0;">
|
|
||||||
<%= t(".options") %>
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<label for="skip_email_confirmation" style="grid-column: 1 / 3; text-align: left;">
|
|
||||||
<%= check_box_tag :skip_email_confirmation, "1",
|
|
||||||
params[:skip_email_confirmation] == "1",
|
|
||||||
id: "skip_email_confirmation" %>
|
|
||||||
<%= t(".skip_email_confirmation") %>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label for="seed_units" style="grid-column: 1 / 3; text-align: left;">
|
|
||||||
<%= check_box_tag :seed_units, "1", true, id: "seed_units" %>
|
|
||||||
<%= t(".seed_units") %>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<%= submit_tag t(".submit") %>
|
|
||||||
<% end %>
|
|
||||||
@@ -54,9 +54,5 @@ module FixinMe
|
|||||||
|
|
||||||
# Sender address of account registration-related messages
|
# Sender address of account registration-related messages
|
||||||
Devise.mailer_sender = 'noreply@localhost'
|
Devise.mailer_sender = 'noreply@localhost'
|
||||||
|
|
||||||
# Whether to skip e-mail confirmation for new registrations is configured
|
|
||||||
# through the web setup wizard and stored in the database (Setting model),
|
|
||||||
# so it does not need to be set here.
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -163,23 +163,6 @@ en:
|
|||||||
<br><em>leave blank to keep unchanged</em>
|
<br><em>leave blank to keep unchanged</em>
|
||||||
%{password_length_hint_html}
|
%{password_length_hint_html}
|
||||||
actions: Actions
|
actions: Actions
|
||||||
setup:
|
|
||||||
new:
|
|
||||||
admin_account: Admin account
|
|
||||||
admin_email: 'E-mail:'
|
|
||||||
admin_password: 'Password:'
|
|
||||||
admin_password_confirmation: 'Retype password:'
|
|
||||||
options: Options
|
|
||||||
skip_email_confirmation: Skip e-mail confirmation for new registrations
|
|
||||||
seed_units: Seed built-in default units
|
|
||||||
submit: Set up
|
|
||||||
create:
|
|
||||||
email_blank: E-mail cannot be blank.
|
|
||||||
password_blank: Password cannot be blank.
|
|
||||||
password_mismatch: Passwords do not match.
|
|
||||||
success: >
|
|
||||||
Installation complete. You can now sign in with the admin account you
|
|
||||||
just created.
|
|
||||||
add: Add
|
add: Add
|
||||||
apply: Apply
|
apply: Apply
|
||||||
back: Back
|
back: Back
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
# Web-based installation wizard — only reachable when no admin exists yet.
|
|
||||||
resource :setup, only: [:new, :create], controller: :setup
|
|
||||||
|
|
||||||
resources :measurements
|
resources :measurements
|
||||||
|
|
||||||
resources :readouts, only: [:new] do
|
resources :readouts, only: [:new] do
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
class CreateSettings < ActiveRecord::Migration[7.2]
|
|
||||||
def change
|
|
||||||
create_table :settings do |t|
|
|
||||||
t.string :key, null: false
|
|
||||||
t.string :value
|
|
||||||
|
|
||||||
t.timestamps
|
|
||||||
end
|
|
||||||
|
|
||||||
add_index :settings, :key, unique: true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
11
db/seeds.rb
11
db/seeds.rb
@@ -3,17 +3,6 @@
|
|||||||
# bin/rails db:seed
|
# bin/rails db:seed
|
||||||
# command (or created alongside the database with db:setup).
|
# command (or created alongside the database with db:setup).
|
||||||
# Seeding process should be idempotent.
|
# Seeding process should be idempotent.
|
||||||
#
|
|
||||||
# Admin account setup
|
|
||||||
# -------------------
|
|
||||||
# The preferred way to create the first admin account is through the web setup
|
|
||||||
# wizard, which is shown automatically on the first visit when no admin exists.
|
|
||||||
# The wizard also lets you configure runtime options (e.g. skip e-mail
|
|
||||||
# confirmation) and seed the default units without using the command line.
|
|
||||||
#
|
|
||||||
# The block below provides an alternative CLI path for headless / automated
|
|
||||||
# deployments. It is skipped when an admin account already exists (e.g. after
|
|
||||||
# the web wizard has run).
|
|
||||||
|
|
||||||
User.transaction do
|
User.transaction do
|
||||||
break if User.find_by status: :admin
|
break if User.find_by status: :admin
|
||||||
|
|||||||
Reference in New Issue
Block a user