このコミットが含まれているのは:
@@ -82,6 +82,16 @@ class CountsCondition
|
||||
|
||||
def apply(scope, entry)
|
||||
raise ArgumentError unless entry.is_a?(Hash)
|
||||
if entry['operator'] == 'axis_eq'
|
||||
raise ArgumentError unless (entry.keys - ['field', 'operator', 'grain', 'value']).empty?
|
||||
value = entry['value']
|
||||
unless value.nil? || value.is_a?(String) || value.is_a?(Numeric)
|
||||
raise ArgumentError
|
||||
end
|
||||
raise ArgumentError if value.is_a?(String) && value.bytesize > 8192
|
||||
|
||||
return @population.axis_condition(scope, entry)
|
||||
end
|
||||
allowed = ['field', 'operator', 'value', 'end', 'blank', 'input', 'values']
|
||||
raise ArgumentError if (entry.keys - allowed).any?
|
||||
|
||||
|
||||
@@ -62,6 +62,29 @@ class CountsPopulation
|
||||
@authorisation_flg ? HistoryAccess.sql(model, row) : 'TRUE'
|
||||
end
|
||||
|
||||
def axis_condition(scope, entry)
|
||||
key = entry.fetch('field')
|
||||
if key == 'tags'
|
||||
scope = scope.where(snapshot_membership(entry.fetch('value')))
|
||||
elsif key == 'changed_field'
|
||||
raise ArgumentError unless history && definition.changes.include?(entry['value'])
|
||||
|
||||
scope = scope.where(Arel.sql(changed_sql(entry['value'])))
|
||||
elsif definition.fields[key] == :datetime && entry['grain']
|
||||
scope = scope.where(definition.expression(key) => nil) if entry['value'].nil?
|
||||
if entry['value']
|
||||
expression = CountsAxes.time_expression(definition.expression(key),
|
||||
entry['grain'], timezone)
|
||||
scope = scope.where("#{ expression } = ?", entry['value'])
|
||||
end
|
||||
else
|
||||
raise ArgumentError unless definition.axes(history).include?(key)
|
||||
|
||||
scope = scope.where(definition.expression(key) => entry['value'])
|
||||
end
|
||||
scope
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def make_population
|
||||
@@ -69,7 +92,8 @@ class CountsPopulation
|
||||
@scope = @scope.from("#{ table } v").select('v.*')
|
||||
previous = ['rows', 'cols'].any? do |key|
|
||||
QueryState.axes(params.fetch(key, '')).any? { _1['field'] == 'changed_field' }
|
||||
end || QueryState.records(params, 'drill').any? { _1['field'] == 'changed_field' }
|
||||
end || (QueryState.records(params, 'drill') + QueryState.records(params, 'conditions'))
|
||||
.any? { _1['field'] == 'changed_field' }
|
||||
if previous
|
||||
keys = definition.keys.map { "previous.#{ _1 } = v.#{ _1 }" }.join(' AND ')
|
||||
@scope = @scope.joins("LEFT JOIN #{ table } previous ON #{ keys } " +
|
||||
@@ -127,25 +151,7 @@ class CountsPopulation
|
||||
raise ArgumentError unless drills.is_a?(Array) && drills.length <= 100
|
||||
|
||||
drills.each do |entry|
|
||||
key = entry.fetch('field')
|
||||
if key == 'tags'
|
||||
@scope = @scope.where(snapshot_membership(entry.fetch('value')))
|
||||
elsif key == 'changed_field'
|
||||
raise ArgumentError unless history && definition.changes.include?(entry['value'])
|
||||
|
||||
@scope = @scope.where(Arel.sql(changed_sql(entry['value'])))
|
||||
elsif definition.fields[key] == :datetime && entry['grain']
|
||||
@scope = @scope.where(definition.expression(key) => nil) if entry['value'].nil?
|
||||
if entry['value']
|
||||
expression = CountsAxes.time_expression(definition.expression(key),
|
||||
entry['grain'], timezone)
|
||||
@scope = @scope.where("#{ expression } = ?", entry['value'])
|
||||
end
|
||||
else
|
||||
raise ArgumentError unless definition.axes(history).include?(key)
|
||||
|
||||
@scope = @scope.where(definition.expression(key) => entry['value'])
|
||||
end
|
||||
@scope = axis_condition(@scope, entry)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Public query grammar shared with frontend/src/lib/queryState.ts.
|
||||
class QueryState
|
||||
SCHEMAS = {
|
||||
'conditions' => ['field', 'operator', 'value', 'end', 'blank', 'input', 'values'],
|
||||
'conditions' => ['field', 'operator', 'value', 'end', 'blank', 'input', 'values', 'grain', 'value_type'],
|
||||
'condition_values' => ['condition', 'value', 'value_type'],
|
||||
'drill' => ['field', 'grain', 'value', 'value_type'],
|
||||
'tag_refs' => ['name', 'tag_id', 'external_tag_id', 'negative', 'missing'],
|
||||
@@ -57,7 +57,8 @@ class QueryState
|
||||
|
||||
records.sort.map do |_index, record|
|
||||
type = record.delete('value_type')
|
||||
if ['drill', 'measures', 'column_order', 'condition_values'].include?(key)
|
||||
if ['drill', 'measures', 'column_order', 'condition_values'].include?(key) ||
|
||||
(key == 'conditions' && record['operator'] == 'axis_eq')
|
||||
raise ArgumentError unless ['null', 'string', 'number', 'boolean'].include?(type)
|
||||
|
||||
raise ArgumentError unless type == 'null' || record.key?('value')
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする