forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #476 from imas/fix/favourite_tags-latin-char
お気に入りタグにおいて、大文字小文字を混在できないバグを修正
- Loading branch information
Showing
22 changed files
with
424 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::FavouriteTagsController < Api::BaseController | ||
before_action :set_account | ||
before_action -> { doorkeeper_authorize! :read, :'read:statuses' }, only: [:index] | ||
before_action -> { doorkeeper_authorize! :write, :'write:statuses' }, except: [:index] | ||
before_action :require_user! | ||
|
||
respond_to :json | ||
|
||
def index | ||
render json: current_favourite_tags | ||
current_account = current_user.account | ||
orderd_favourite_tags = current_account.favourite_tags.with_order | ||
|
||
render json: orderd_favourite_tags.map(&:to_json_for_api) | ||
end | ||
|
||
def create | ||
tag = find_or_init_tag | ||
@favourite_tag = FavouriteTag.new(account: @account, tag: tag, visibility: favourite_tag_visibility) | ||
if @favourite_tag.save | ||
render json: @favourite_tag.to_json_for_api | ||
else | ||
render json: find_fav_tag_by(tag).to_json_for_api, status: 409 | ||
current_account = current_user.account | ||
favourite_tag = current_account.favourite_tags.find_by(name: create_params[:name], visibility: create_params[:visibility]) | ||
|
||
if favourite_tag.present? | ||
render json: favourite_tag.to_json_for_api, status: 409 | ||
return | ||
end | ||
|
||
favourite_tag = FavouriteTag.new(account: current_account, name: create_params[:name], visibility: create_params[:visibility]) | ||
favourite_tag.save! | ||
render json: favourite_tag.to_json_for_api | ||
end | ||
|
||
def destroy | ||
tag = find_tag | ||
@favourite_tag = find_fav_tag_by(tag) | ||
if @favourite_tag.nil? | ||
render json: { succeeded: false }, status: 404 | ||
current_account = current_user.account | ||
favourite_tag = current_account.favourite_tags.find_by(id: params[:id]) | ||
if favourite_tag.nil? | ||
render json: { error: 'FavouriteTag is not found' }, status: 404 | ||
else | ||
@favourite_tag.destroy | ||
render json: { succeeded: true } | ||
favourite_tag.destroy! | ||
end | ||
end | ||
|
||
private | ||
|
||
def tag_params | ||
params.permit(:tag, :visibility) | ||
end | ||
|
||
def set_account | ||
@account = current_user.account | ||
end | ||
|
||
def find_or_init_tag | ||
Tag.find_or_initialize_by(name: tag_params[:tag]) | ||
end | ||
|
||
def find_tag | ||
Tag.find_by(name: tag_params[:tag]) | ||
end | ||
|
||
def find_fav_tag_by(tag) | ||
@account.favourite_tags.find_by(tag: tag) | ||
end | ||
|
||
def favourite_tag_visibility | ||
tag_params[:visibility].nil? ? 'public' : tag_params[:visibility] | ||
end | ||
|
||
def current_favourite_tags | ||
current_account.favourite_tags.with_order.includes(:tag).map(&:to_json_for_api) | ||
def create_params | ||
params.permit(:name, :visibility) | ||
params[:visibility] ||= 'public' | ||
params | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.