forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Wip * Wip * Wip: History * Wip: テストコード作成 * Fix test * Wip * Wip * Wip * Fix test * Wip * Wip * Wip * Wip * なんとか完成、これから動作確認 * spell miss * Change ng rule timings * Fix test * Wip * Fix test * Wip * Fix form * 表示まわりの改善
- Loading branch information
Showing
56 changed files
with
2,061 additions
and
41 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class NgRuleHistoriesController < BaseController | ||
before_action :set_ng_rule | ||
before_action :set_histories | ||
|
||
PER_PAGE = 20 | ||
|
||
def show | ||
authorize :ng_words, :show? | ||
end | ||
|
||
private | ||
|
||
def set_ng_rule | ||
@ng_rule = ::NgRule.find(params[:id]) | ||
end | ||
|
||
def set_histories | ||
@histories = NgRuleHistory.where(ng_rule_id: params[:id]).order(id: :desc).page(params[:page]).per(PER_PAGE) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class NgRulesController < BaseController | ||
before_action :set_ng_rule, only: [:edit, :update, :destroy, :duplicate] | ||
|
||
def index | ||
authorize :ng_words, :show? | ||
|
||
@ng_rules = ::NgRule.order(id: :asc) | ||
end | ||
|
||
def new | ||
authorize :ng_words, :show? | ||
|
||
@ng_rule = ::NgRule.build | ||
end | ||
|
||
def edit | ||
authorize :ng_words, :show? | ||
end | ||
|
||
def create | ||
authorize :ng_words, :create? | ||
|
||
begin | ||
test_words! | ||
rescue | ||
flash[:alert] = I18n.t('admin.ng_rules.test_error') | ||
redirect_to new_admin_ng_rule_path | ||
return | ||
end | ||
|
||
@ng_rule = ::NgRule.build(resource_params) | ||
|
||
if @ng_rule.save | ||
redirect_to admin_ng_rules_path | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
authorize :ng_words, :create? | ||
|
||
begin | ||
test_words! | ||
rescue | ||
flash[:alert] = I18n.t('admin.ng_rules.test_error') | ||
redirect_to edit_admin_ng_rule_path(id: @ng_rule.id) | ||
return | ||
end | ||
|
||
if @ng_rule.update(resource_params) | ||
redirect_to admin_ng_rules_path | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def duplicate | ||
authorize :ng_words, :create? | ||
|
||
@ng_rule = @ng_rule.copy! | ||
|
||
flash[:alert] = I18n.t('admin.ng_rules.copy_error') unless @ng_rule.save | ||
|
||
redirect_to admin_ng_rules_path | ||
end | ||
|
||
def destroy | ||
authorize :ng_words, :create? | ||
|
||
@ng_rule.destroy | ||
redirect_to admin_ng_rules_path | ||
end | ||
|
||
private | ||
|
||
def set_ng_rule | ||
@ng_rule = ::NgRule.find(params[:id]) | ||
end | ||
|
||
def resource_params | ||
params.require(:ng_rule).permit(:title, :expires_in, :available, :account_domain, :account_username, :account_display_name, | ||
:account_note, :account_field_name, :account_field_value, :account_avatar_state, | ||
:account_header_state, :account_include_local, :status_spoiler_text, :status_text, :status_tag, | ||
:status_sensitive_state, :status_cw_state, :status_media_state, :status_poll_state, | ||
:status_mention_state, :status_reference_state, | ||
:status_quote_state, :status_reply_state, :status_media_threshold, :status_poll_threshold, | ||
:status_mention_threshold, :status_allow_follower_mention, | ||
:reaction_allow_follower, :emoji_reaction_name, :emoji_reaction_origin_domain, | ||
:status_reference_threshold, :account_allow_followed_by_local, :record_history_also_local, | ||
status_visibility: [], status_searchability: [], reaction_type: []) | ||
end | ||
|
||
def test_words! | ||
arr = [ | ||
resource_params[:account_domain], | ||
resource_params[:account_username], | ||
resource_params[:account_display_name], | ||
resource_params[:account_note], | ||
resource_params[:account_field_name], | ||
resource_params[:account_field_value], | ||
resource_params[:status_spoiler_text], | ||
resource_params[:status_text], | ||
resource_params[:status_tag], | ||
resource_params[:emoji_reaction_name], | ||
resource_params[:emoji_reaction_origin_domain], | ||
].compact_blank.join("\n") | ||
|
||
Admin::NgRule.extract_test!(arr) if arr.present? | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module NgRuleHelper | ||
def check_invalid_status_for_ng_rule!(account, **options) | ||
(check_for_ng_rule!(account, **options) { |rule| !rule.check_status_or_record! }).none? | ||
end | ||
|
||
def check_invalid_reaction_for_ng_rule!(account, **options) | ||
(check_for_ng_rule!(account, **options) { |rule| !rule.check_reaction_or_record! }).none? | ||
end | ||
|
||
private | ||
|
||
def check_for_ng_rule!(account, **options, &block) | ||
NgRule.cached_rules | ||
.map { |raw_rule| Admin::NgRule.new(raw_rule, account, **options) } | ||
.filter(&block) | ||
end | ||
|
||
def do_account_action_for_rule!(account, action) | ||
case action | ||
when :silence | ||
account.silence! | ||
when :suspend | ||
account.suspend! | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class Vacuum::NgHistoriesVacuum | ||
include Redisable | ||
|
||
HISTORY_LIFE_DURATION = 7.days.freeze | ||
|
||
def perform | ||
vacuum_histories! | ||
end | ||
|
||
private | ||
|
||
def vacuum_histories! | ||
NgRuleHistory.where('created_at < ?', HISTORY_LIFE_DURATION.ago).in_batches.destroy_all | ||
end | ||
end |
Oops, something went wrong.