From 78b5b063fce4783ddb345f9c87b05bb6490e2209 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Tue, 4 Jul 2023 00:40:06 -0700 Subject: [PATCH] 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 --- app/blueprints/api/v1/party_blueprint.rb | 8 ++--- .../api/v1/grid_summons_controller.rb | 10 +++---- app/controllers/api/v1/parties_controller.rb | 3 +- app/controllers/api/v1/users_controller.rb | 30 ++++++++----------- app/models/party.rb | 3 +- ...02035600_populate_remix_flag_on_parties.rb | 15 ++++++++++ db/data_schema.rb | 2 +- ...0230702035508_add_remix_flag_to_parties.rb | 5 ++++ db/schema.rb | 3 +- 9 files changed, 47 insertions(+), 32 deletions(-) create mode 100644 db/data/20230702035600_populate_remix_flag_on_parties.rb create mode 100644 db/migrate/20230702035508_add_remix_flag_to_parties.rb diff --git a/app/blueprints/api/v1/party_blueprint.rb b/app/blueprints/api/v1/party_blueprint.rb index ef5ba48..0605210 100644 --- a/app/blueprints/api/v1/party_blueprint.rb +++ b/app/blueprints/api/v1/party_blueprint.rb @@ -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, diff --git a/app/controllers/api/v1/grid_summons_controller.rb b/app/controllers/api/v1/grid_summons_controller.rb index f55101c..156fcd6 100644 --- a/app/controllers/api/v1/grid_summons_controller.rb +++ b/app/controllers/api/v1/grid_summons_controller.rb @@ -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. diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index 8dec3bd..aa78acd 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -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? diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index d290c93..2f658a1 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -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 diff --git a/app/models/party.rb b/app/models/party.rb index 988cefd..122eeb7 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -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 diff --git a/db/data/20230702035600_populate_remix_flag_on_parties.rb b/db/data/20230702035600_populate_remix_flag_on_parties.rb new file mode 100644 index 0000000..a4f2ebf --- /dev/null +++ b/db/data/20230702035600_populate_remix_flag_on_parties.rb @@ -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 diff --git a/db/data_schema.rb b/db/data_schema.rb index e0e6836..439fbc9 100644 --- a/db/data_schema.rb +++ b/db/data_schema.rb @@ -1 +1 @@ -DataMigrate::Data.define(version: 20230619043726) +DataMigrate::Data.define(version: 20230702035600) diff --git a/db/migrate/20230702035508_add_remix_flag_to_parties.rb b/db/migrate/20230702035508_add_remix_flag_to_parties.rb new file mode 100644 index 0000000..571492a --- /dev/null +++ b/db/migrate/20230702035508_add_remix_flag_to_parties.rb @@ -0,0 +1,5 @@ +class AddRemixFlagToParties < ActiveRecord::Migration[7.0] + def change + add_column :parties, :remix, :boolean, default: false, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 9f52e13..0dd39f7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"