Deploy July Quality Update (#114)
* Remove print statements from data migration * (Hotfix) Fix data migration failing due to nil * Fix stale migration errors * Ensure new characters have Awakenings Every character starts with Balanced Lv1 awakening * Ensure weapons without awakenings do not expose key * Updates database seeds (#109) * Destroy favorites when a party is deleted * Allow users to delete parties with remixes (#111) There was a bug that prevented users from deleting parties with remixes, because the source party reference was not being nulled. We fixed that with `dependent: :nullify` but also added a boolean key to the parties database to track if a party is a remix or not. This way, if a party is flagged as a remix but the source party is null, we know that the original party was deleted and can message this on the frontend. * Fix deleting grid summons (#112) A bad decision to try to reduce code in `set` made this fail with a 422 because `summon_params` was being tested against but... didn't exist? was nil? I fixed it by not using `set` before calling `destroy`, and just finding the summon in the `destroy` method itself * Usernames in URLs should not be case-sensitive (#113) Amateur hour mistake * Change default filters in users controller
This commit is contained in:
parent
293e94437b
commit
78b5b063fc
9 changed files with 47 additions and 32 deletions
|
|
@ -33,14 +33,10 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
view :minimal do
|
view :minimal do
|
||||||
fields :name, :element, :shortcode, :favorited, :extra,
|
fields :name, :element, :shortcode, :favorited, :remix,
|
||||||
:full_auto, :clear_time, :auto_guard, :auto_summon,
|
:extra, :full_auto, :clear_time, :auto_guard, :auto_summon,
|
||||||
:created_at, :updated_at
|
:created_at, :updated_at
|
||||||
|
|
||||||
field :remix do |p|
|
|
||||||
p.is_remix
|
|
||||||
end
|
|
||||||
|
|
||||||
field :guidebooks do |p|
|
field :guidebooks do |p|
|
||||||
{
|
{
|
||||||
'1' => !p.guidebook1.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook1) : nil,
|
'1' => !p.guidebook1.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook1) : nil,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ module Api
|
||||||
class GridSummonsController < Api::V1::ApiController
|
class GridSummonsController < Api::V1::ApiController
|
||||||
attr_reader :party, :incoming_summon
|
attr_reader :party, :incoming_summon
|
||||||
|
|
||||||
before_action :set, only: %w[update update_uncap_level update_quick_summon destroy]
|
before_action :set, only: %w[update update_uncap_level update_quick_summon]
|
||||||
before_action :find_party, only: :create
|
before_action :find_party, only: :create
|
||||||
before_action :find_incoming_summon, only: :create
|
before_action :find_incoming_summon, only: :create
|
||||||
before_action :authorize, only: %i[create update update_uncap_level update_quick_summon destroy]
|
before_action :authorize, only: %i[create update update_uncap_level update_quick_summon destroy]
|
||||||
|
|
@ -111,8 +111,9 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
render_unauthorized_response if @summon.party.user != current_user
|
summon = GridSummon.find_by('id = ?', params[:id])
|
||||||
return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy
|
render_unauthorized_response if summon.party.user != current_user
|
||||||
|
return render json: GridSummonBlueprint.render(summon, view: :destroyed) if summon.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
@ -142,8 +143,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def set
|
def set
|
||||||
id = summon_params[:id] ? summon_params[:id] : params[:id]
|
@summon = GridSummon.find_by('id = ?', summon_params[:id])
|
||||||
@summon = GridSummon.where('id = ?', id).first
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Specify whitelisted properties that can be modified.
|
# Specify whitelisted properties that can be modified.
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,8 @@ module Api
|
||||||
new_party.attributes = {
|
new_party.attributes = {
|
||||||
user: current_user,
|
user: current_user,
|
||||||
name: remixed_name(@party.name),
|
name: remixed_name(@party.name),
|
||||||
source_party: @party
|
source_party: @party,
|
||||||
|
remix: true
|
||||||
}
|
}
|
||||||
|
|
||||||
new_party.local_id = party_params[:local_id] if !party_params.nil?
|
new_party.local_id = party_params[:local_id] if !party_params.nil?
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ module Api
|
||||||
MAX_SUMMONS = 8
|
MAX_SUMMONS = 8
|
||||||
MAX_WEAPONS = 13
|
MAX_WEAPONS = 13
|
||||||
|
|
||||||
DEFAULT_MIN_CHARACTERS = 3
|
DEFAULT_MIN_CHARACTERS = 0
|
||||||
DEFAULT_MIN_SUMMONS = 2
|
DEFAULT_MIN_SUMMONS = 0
|
||||||
DEFAULT_MIN_WEAPONS = 5
|
DEFAULT_MIN_WEAPONS = 0
|
||||||
|
|
||||||
DEFAULT_MAX_CLEAR_TIME = 5400
|
DEFAULT_MAX_CLEAR_TIME = 5400
|
||||||
|
|
||||||
|
|
@ -53,19 +53,9 @@ module Api
|
||||||
if @user.nil?
|
if @user.nil?
|
||||||
render_not_found_response('user')
|
render_not_found_response('user')
|
||||||
else
|
else
|
||||||
|
|
||||||
conditions = build_conditions
|
conditions = build_conditions
|
||||||
conditions[:user_id] = @user.id
|
conditions[:user_id] = @user.id
|
||||||
|
|
||||||
@parties = Party
|
|
||||||
.where(conditions)
|
|
||||||
.where(name_quality)
|
|
||||||
.where(user_quality)
|
|
||||||
.where(original)
|
|
||||||
.order(created_at: :desc)
|
|
||||||
.paginate(page: request.params[:page], per_page: COLLECTION_PER_PAGE)
|
|
||||||
.each { |party| party.favorited = party.is_favorited(current_user) }
|
|
||||||
|
|
||||||
parties = Party
|
parties = Party
|
||||||
.where(conditions)
|
.where(conditions)
|
||||||
.where(name_quality)
|
.where(name_quality)
|
||||||
|
|
@ -141,11 +131,15 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def original
|
def original
|
||||||
"source_party_id IS NULL" unless params['original'].blank? || params['original'] == '0'
|
unless params.key?('original') || params['original'].blank? || params['original'] == '0'
|
||||||
|
"source_party_id IS NULL"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_quality
|
def user_quality
|
||||||
"user_id IS NOT NULL" unless params[:user_quality].nil? || params[:user_quality] == "0"
|
unless params.key?('user_quality') || params[:user_quality].nil? || params[:user_quality] == "0"
|
||||||
|
"user_id IS NOT NULL"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def name_quality
|
def name_quality
|
||||||
|
|
@ -166,12 +160,14 @@ module Api
|
||||||
|
|
||||||
joined_names = low_quality.map { |name| "'#{name}'" }.join(',')
|
joined_names = low_quality.map { |name| "'#{name}'" }.join(',')
|
||||||
|
|
||||||
"name NOT IN (#{joined_names})" unless params[:name_quality].nil? || params[:name_quality] == "0"
|
unless params.key?('name_quality') || params[:name_quality].nil? || params[:name_quality] == "0"
|
||||||
|
"name NOT IN (#{joined_names})"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Specify whitelisted properties that can be modified.
|
# Specify whitelisted properties that can be modified.
|
||||||
def set
|
def set
|
||||||
@user = User.where('username = ?', params[:id]).first
|
@user = User.where('username = ?', params[:id].downcase).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_by_id
|
def set_by_id
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ class Party < ApplicationRecord
|
||||||
has_many :derivative_parties,
|
has_many :derivative_parties,
|
||||||
class_name: 'Party',
|
class_name: 'Party',
|
||||||
foreign_key: :source_party_id,
|
foreign_key: :source_party_id,
|
||||||
inverse_of: :source_party
|
inverse_of: :source_party,
|
||||||
|
dependent: :nullify
|
||||||
|
|
||||||
belongs_to :user, optional: true
|
belongs_to :user, optional: true
|
||||||
belongs_to :raid, optional: true
|
belongs_to :raid, optional: true
|
||||||
|
|
|
||||||
15
db/data/20230702035600_populate_remix_flag_on_parties.rb
Normal file
15
db/data/20230702035600_populate_remix_flag_on_parties.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class PopulateRemixFlagOnParties < ActiveRecord::Migration[7.0]
|
||||||
|
def up
|
||||||
|
Party.find_each do |party|
|
||||||
|
party.update(remix: party.source_party_id.present?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
Party.find_each do |party|
|
||||||
|
party.update(remix: false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1 +1 @@
|
||||||
DataMigrate::Data.define(version: 20230619043726)
|
DataMigrate::Data.define(version: 20230702035600)
|
||||||
|
|
|
||||||
5
db/migrate/20230702035508_add_remix_flag_to_parties.rb
Normal file
5
db/migrate/20230702035508_add_remix_flag_to_parties.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddRemixFlagToParties < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
add_column :parties, :remix, :boolean, default: false, null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_06_21_073125) do
|
ActiveRecord::Schema[7.0].define(version: 2023_07_02_035508) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "btree_gin"
|
enable_extension "btree_gin"
|
||||||
enable_extension "pg_trgm"
|
enable_extension "pg_trgm"
|
||||||
|
|
@ -347,6 +347,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_21_073125) do
|
||||||
t.uuid "guidebook1_id"
|
t.uuid "guidebook1_id"
|
||||||
t.uuid "guidebook2_id"
|
t.uuid "guidebook2_id"
|
||||||
t.boolean "auto_summon", default: false, null: false
|
t.boolean "auto_summon", default: false, null: false
|
||||||
|
t.boolean "remix", default: false, null: false
|
||||||
t.index ["accessory_id"], name: "index_parties_on_accessory_id"
|
t.index ["accessory_id"], name: "index_parties_on_accessory_id"
|
||||||
t.index ["guidebook1_id"], name: "index_parties_on_guidebook1_id"
|
t.index ["guidebook1_id"], name: "index_parties_on_guidebook1_id"
|
||||||
t.index ["guidebook2_id"], name: "index_parties_on_guidebook2_id"
|
t.index ["guidebook2_id"], name: "index_parties_on_guidebook2_id"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue