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:
Justin Edmund 2023-07-04 00:40:06 -07:00 committed by GitHub
parent 293e94437b
commit 78b5b063fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 47 additions and 32 deletions

View file

@ -33,14 +33,10 @@ module Api
end
view :minimal do
fields :name, :element, :shortcode, :favorited, :extra,
:full_auto, :clear_time, :auto_guard, :auto_summon,
fields :name, :element, :shortcode, :favorited, :remix,
:extra, :full_auto, :clear_time, :auto_guard, :auto_summon,
:created_at, :updated_at
field :remix do |p|
p.is_remix
end
field :guidebooks do |p|
{
'1' => !p.guidebook1.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook1) : nil,

View file

@ -5,7 +5,7 @@ module Api
class GridSummonsController < Api::V1::ApiController
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_incoming_summon, only: :create
before_action :authorize, only: %i[create update update_uncap_level update_quick_summon destroy]
@ -111,8 +111,9 @@ module Api
end
def destroy
render_unauthorized_response if @summon.party.user != current_user
return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy
summon = GridSummon.find_by('id = ?', params[:id])
render_unauthorized_response if summon.party.user != current_user
return render json: GridSummonBlueprint.render(summon, view: :destroyed) if summon.destroy
end
private
@ -142,8 +143,7 @@ module Api
end
def set
id = summon_params[:id] ? summon_params[:id] : params[:id]
@summon = GridSummon.where('id = ?', id).first
@summon = GridSummon.find_by('id = ?', summon_params[:id])
end
# Specify whitelisted properties that can be modified.

View file

@ -69,7 +69,8 @@ module Api
new_party.attributes = {
user: current_user,
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?

View file

@ -12,9 +12,9 @@ module Api
MAX_SUMMONS = 8
MAX_WEAPONS = 13
DEFAULT_MIN_CHARACTERS = 3
DEFAULT_MIN_SUMMONS = 2
DEFAULT_MIN_WEAPONS = 5
DEFAULT_MIN_CHARACTERS = 0
DEFAULT_MIN_SUMMONS = 0
DEFAULT_MIN_WEAPONS = 0
DEFAULT_MAX_CLEAR_TIME = 5400
@ -53,19 +53,9 @@ module Api
if @user.nil?
render_not_found_response('user')
else
conditions = build_conditions
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
.where(conditions)
.where(name_quality)
@ -141,11 +131,15 @@ module Api
end
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
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
def name_quality
@ -166,12 +160,14 @@ module Api
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
# Specify whitelisted properties that can be modified.
def set
@user = User.where('username = ?', params[:id]).first
@user = User.where('username = ?', params[:id].downcase).first
end
def set_by_id

View file

@ -10,7 +10,8 @@ class Party < ApplicationRecord
has_many :derivative_parties,
class_name: 'Party',
foreign_key: :source_party_id,
inverse_of: :source_party
inverse_of: :source_party,
dependent: :nullify
belongs_to :user, optional: true
belongs_to :raid, optional: true

View 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

View file

@ -1 +1 @@
DataMigrate::Data.define(version: 20230619043726)
DataMigrate::Data.define(version: 20230702035600)

View file

@ -0,0 +1,5 @@
class AddRemixFlagToParties < ActiveRecord::Migration[7.0]
def change
add_column :parties, :remix, :boolean, default: false, null: false
end
end

View file

@ -10,7 +10,7 @@
#
# 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
enable_extension "btree_gin"
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 "guidebook2_id"
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 ["guidebook1_id"], name: "index_parties_on_guidebook1_id"
t.index ["guidebook2_id"], name: "index_parties_on_guidebook2_id"