* Implements advanced filters (#90) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix a bug where unauthenticated users couldn't view profiles (#92) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix being unable to see profiles when unauth * Add tables used for Siero's revival (#94) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Deploy unauthenticated profile fix (#93) * Implements advanced filters (#90) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix a bug where unauthenticated users couldn't view profiles (#92) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix being unable to see profiles when unauth * Add guidebooks migration * Implement business logic for reading Guidebooks * Change to individual guidebook columns * Properly output guidebook description * Move to 1-index guidebooks * Update party-related files for 1-index guidebooks * Add tables for Siero * Update download and export scripts * Support for Siero, raids rework and edit party rework (#96) * Add guidebooks migration * Implement business logic for reading Guidebooks * Change to individual guidebook columns * Properly output guidebook description * Move to 1-index guidebooks * Update party-related files for 1-index guidebooks * Add tables for Siero * Add raid groups table * Update raid model To belong to the RaidGroup class * Update job class To have many job skills * Add endpoint for raid groups * Update Raid blueprint with views * Added down for creating table * Add guidebooks flag and auto summon flag * Guidebooks → RaidGroup * Auto summon → Party * Add views to Raid blueprint * Add views and guidebook flag to RaidGroup blueprint * Add auto summon and Raid view to Party blueprint * Add quick summons (#97) * Adds quick summon migration * Add route to update quick summon * Add logic to update quick summon * Remove ap call * Add logic to updating summon uncap You couldn't actually update summon transcendence on staging, maybe due to a bug? Now you can. And it won't let you update outside of the bounds of what is defined on the canonical object. * Fix summon logic Updated logic for updating summon uncap and transcendence levels and quick summon status. * Fix searching in Japanese (#99) This was broken because we were using the browser-provided locale as a prefix to our method, but that is 'ja' and our methods were prefixed with 'jp'. * Fix display of base skills (#100) Base skills were not displaying due to a missing case in our search code. This is now fixed. * Update awakenings (#101) * Deploy unauthenticated profile fix (#93) * Implements advanced filters (#90) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix a bug where unauthenticated users couldn't view profiles (#92) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix being unable to see profiles when unauth * Add tables used for Siero's revival (#94) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Deploy unauthenticated profile fix (#93) * Implements advanced filters (#90) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix a bug where unauthenticated users couldn't view profiles (#92) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix being unable to see profiles when unauth * Add guidebooks migration * Implement business logic for reading Guidebooks * Change to individual guidebook columns * Properly output guidebook description * Move to 1-index guidebooks * Update party-related files for 1-index guidebooks * Add tables for Siero * Adds guidebooks and gacha tables (#95) * Implements advanced filters (#90) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix a bug where unauthenticated users couldn't view profiles (#92) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix being unable to see profiles when unauth * Add tables used for Siero's revival (#94) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Deploy unauthenticated profile fix (#93) * Implements advanced filters (#90) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix a bug where unauthenticated users couldn't view profiles (#92) * Implements advanced filters (#90) (#91) * Add advanced filters Adds new filters to search: * Full auto * Charge attack * Auto guard * Number of weapons (user-selectable now) * Number of summons * Number of characters * Maximum number of turns * Maximum number of buttons * Maximum clear time * User quality (No anonymous users) * Name quality (No untitled teams) * Remixes (Only show original teams) * Update advanced filter params * Add default to party counter cache * Fix being unable to see profiles when unauth * Add guidebooks migration * Implement business logic for reading Guidebooks * Change to individual guidebook columns * Properly output guidebook description * Move to 1-index guidebooks * Update party-related files for 1-index guidebooks * Add tables for Siero * Update download and export scripts * Support for Siero, raids rework and edit party rework (#96) * Add guidebooks migration * Implement business logic for reading Guidebooks * Change to individual guidebook columns * Properly output guidebook description * Move to 1-index guidebooks * Update party-related files for 1-index guidebooks * Add tables for Siero * Add raid groups table * Update raid model To belong to the RaidGroup class * Update job class To have many job skills * Add endpoint for raid groups * Update Raid blueprint with views * Added down for creating table * Add guidebooks flag and auto summon flag * Guidebooks → RaidGroup * Auto summon → Party * Add views to Raid blueprint * Add views and guidebook flag to RaidGroup blueprint * Add auto summon and Raid view to Party blueprint * Remove ap call * Add quick summons (#97) * Adds quick summon migration * Add route to update quick summon * Add logic to update quick summon * Add logic to updating summon uncap You couldn't actually update summon transcendence on staging, maybe due to a bug? Now you can. And it won't let you update outside of the bounds of what is defined on the canonical object. * Fix summon logic Updated logic for updating summon uncap and transcendence levels and quick summon status. * Fix searching in Japanese (#99) This was broken because we were using the browser-provided locale as a prefix to our method, but that is 'ja' and our methods were prefixed with 'jp'. * Fix display of base skills (#100) Base skills were not displaying due to a missing case in our search code. This is now fixed. * Squash migrations into one file * Add migrations This adds migrations and data migrations for the awakening update. * A new `Awakenings` table now exists that stores all possible awakenings, with a column for object type. * GridCharacter and GridWeapon now have `awakening_id` and `awakening_level` fields. Their `awakening` and `awakening_type` fields were removed. * Weapons have a mapping table, `WeaponAwakenings`, as not all weapons can be awakened. * Data migrations are included to migrate existing user data. They should be run automatically when the migration is run with `rails db:migrate:with_data` * Add and update models This updates models for the awakening update. * Awakening and WeaponAwakening models were added * Weapon, GridWeapon and GridCharacter models get relationships to the new models defined * GridCharacter had a validation on `awakening_level` that needed to be fixed * Update controllers This updates the GridCharacters and GridWeapons controllers to accept the new fields `awakening_id` and `awakening_level` from clients * Update blueprints This updates the blueprints to match the new schema. The new AwakeningBlueprint was accidentally added already, oops. * Remove re-added migrations * Implement removing job skills (#103) This lets users remove job skills, for if they accidentally set them. * Fix migration
156 lines
5.2 KiB
Ruby
156 lines
5.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Api
|
|
module V1
|
|
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 :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]
|
|
|
|
def create
|
|
# Create the GridSummon with the desired parameters
|
|
summon = GridSummon.new
|
|
summon.attributes = summon_params.merge(party_id: party.id, summon_id: incoming_summon.id)
|
|
|
|
if summon.validate
|
|
save_summon(summon)
|
|
else
|
|
handle_conflict(summon)
|
|
end
|
|
end
|
|
|
|
def update
|
|
@summon.attributes = summon_params
|
|
|
|
return render json: GridSummonBlueprint.render(@summon, view: :nested, root: :grid_summon) if @summon.save
|
|
|
|
render_validation_error_response(@character)
|
|
end
|
|
|
|
def update_uncap_level
|
|
summon = @summon.summon
|
|
max_uncap_level = if summon.flb && !summon.ulb
|
|
4
|
|
elsif summon.ulb
|
|
5
|
|
else
|
|
3
|
|
end
|
|
|
|
greater_than_max_uncap = summon_params[:uncap_level].to_i > max_uncap_level
|
|
can_be_transcended = summon.xlb && summon_params[:transcendence_step] && summon_params[:transcendence_step]&.to_i.positive?
|
|
|
|
uncap_level = if greater_than_max_uncap || can_be_transcended
|
|
max_uncap_level
|
|
else
|
|
summon_params[:uncap_level]
|
|
end
|
|
|
|
transcendence_step = if summon.xlb && summon_params[:transcendence_step]
|
|
summon_params[:transcendence_step]
|
|
else
|
|
0
|
|
end
|
|
|
|
@summon.update!(
|
|
uncap_level: uncap_level,
|
|
transcendence_step: transcendence_step
|
|
)
|
|
|
|
return unless @summon.persisted?
|
|
|
|
render json: GridSummonBlueprint.render(@summon, view: :nested, root: :grid_summon)
|
|
end
|
|
|
|
def update_quick_summon
|
|
return if [4, 5, 6].include?(@summon.position)
|
|
|
|
quick_summons = @summon.party.summons.select(&:quick_summon)
|
|
|
|
quick_summons.each do |summon|
|
|
summon.update!(quick_summon: false)
|
|
end
|
|
|
|
@summon.update!(quick_summon: summon_params[:quick_summon])
|
|
return unless @summon.persisted?
|
|
|
|
quick_summons -= [@summon]
|
|
summons = [@summon] + quick_summons
|
|
|
|
render json: GridSummonBlueprint.render(summons, view: :nested, root: :summons)
|
|
end
|
|
|
|
def save_summon(summon)
|
|
if (grid_summon = GridSummon.where(
|
|
party_id: party.id,
|
|
position: summon_params[:position]
|
|
).first)
|
|
GridSummon.destroy(grid_summon.id)
|
|
end
|
|
|
|
return unless summon.save
|
|
|
|
output = render_grid_summon_view(summon)
|
|
render json: output, status: :created
|
|
end
|
|
|
|
def handle_conflict(summon)
|
|
conflict_summon = summon.conflicts(party)
|
|
return unless conflict_summon.summon.id == incoming_summon.id
|
|
|
|
old_position = conflict_summon.position
|
|
conflict_summon.position = summon_params[:position]
|
|
|
|
return unless conflict_summon.save
|
|
|
|
output = render_grid_summon_view(conflict_summon, old_position)
|
|
render json: output
|
|
end
|
|
|
|
def destroy
|
|
render_unauthorized_response if @summon.party.user != current_user
|
|
return render json: GridSummonBlueprint.render(@summon, view: :destroyed) if @summon.destroy
|
|
end
|
|
|
|
private
|
|
|
|
def find_incoming_summon
|
|
@incoming_summon = Summon.find_by(id: summon_params[:summon_id])
|
|
end
|
|
|
|
def find_party
|
|
# BUG: I can create grid weapons even when I'm not logged in on an authenticated party
|
|
@party = Party.find(summon_params[:party_id])
|
|
render_unauthorized_response if current_user && (party.user != current_user)
|
|
end
|
|
|
|
def render_grid_summon_view(grid_summon, conflict_position = nil)
|
|
GridSummonBlueprint.render(grid_summon, view: :nested,
|
|
root: :grid_summon,
|
|
meta: { replaced: conflict_position })
|
|
end
|
|
|
|
def authorize
|
|
# Create
|
|
unauthorized_create = @party && (@party.user != current_user || @party.edit_key != edit_key)
|
|
unauthorized_update = @summon && @summon.party && (@summon.party.user != current_user || @summon.party.edit_key != edit_key)
|
|
|
|
render_unauthorized_response if unauthorized_create || unauthorized_update
|
|
end
|
|
|
|
def set
|
|
id = summon_params[:id] ? summon_params[:id] : params[:id]
|
|
@summon = GridSummon.where('id = ?', id).first
|
|
end
|
|
|
|
# Specify whitelisted properties that can be modified.
|
|
def summon_params
|
|
params.require(:summon).permit(:id, :party_id, :summon_id, :position, :main, :friend,
|
|
:quick_summon, :uncap_level, :transcendence_step)
|
|
end
|
|
end
|
|
end
|
|
end
|