Skip to content

Commit

Permalink
Revert "DEV: move post flags into database (#26951)" (#27102)
Browse files Browse the repository at this point in the history
This reverts commit 7aff980.
  • Loading branch information
lis2 authored and CvX committed May 21, 2024
1 parent b3df30f commit dbd21e9
Show file tree
Hide file tree
Showing 28 changed files with 83 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ export default Component.extend({

@discourseComputed("flag.name_key")
customPlaceholder(nameKey) {
return I18n.t("flagging.custom_placeholder_" + nameKey, {
defaultValue: I18n.t("flagging.custom_placeholder_notify_moderators"),
});
return I18n.t("flagging.custom_placeholder_" + nameKey);
},

@discourseComputed("flag.name", "flag.name_key", "username")
formattedName(name, nameKey, username) {
if (["notify_user", "notify_moderators"].includes(nameKey)) {
return name.replace(/{{username}}|%{username}/, username);
} else {
return I18n.t("flagging.formatted_name." + nameKey, {
defaultValue: name,
});
return I18n.t("flagging.formatted_name." + nameKey);
}
},

Expand Down
6 changes: 1 addition & 5 deletions app/assets/javascripts/discourse/app/lib/transform-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,7 @@ export default function transformPost(
postId: post.id,
action,
canUndo: a.can_undo,
description: I18n.t(`post.actions.by_you.${action}`, {
defaultValue: I18n.t(`post.actions.by_you.custom`, {
custom: a.actionType.name,
}),
}),
description: I18n.t(`post.actions.by_you.${action}`),
};
});
}
Expand Down
61 changes: 0 additions & 61 deletions app/models/flag.rb

This file was deleted.

43 changes: 25 additions & 18 deletions app/models/post_action_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def replace_flag_settings(settings)
if settings
@flag_settings = settings
else
reload_types
initialize_flag_settings
end
@types = nil
end
Expand Down Expand Up @@ -79,27 +79,34 @@ def is_flag?(sym)
flag_types.valid?(sym)
end

def reload_types
@types = nil
private

def initialize_flag_settings
@flag_settings = FlagSettings.new
Flag
.enabled
.order(:position)
.each do |flag|
@flag_settings.add(
flag.id,
flag.name_key.to_sym,
topic_type: flag.applies_to?("Topic"),
notify_type: flag.notify_type,
auto_action_type: flag.auto_action_type,
custom_type: flag.custom_type,
name: flag.name,
)
end
@flag_settings.add(3, :off_topic, notify_type: true, auto_action_type: true)
@flag_settings.add(
4,
:inappropriate,
topic_type: true,
notify_type: true,
auto_action_type: true,
)
@flag_settings.add(8, :spam, topic_type: true, notify_type: true, auto_action_type: true)
@flag_settings.add(6, :notify_user, topic_type: false, notify_type: false, custom_type: true)
@flag_settings.add(
7,
:notify_moderators,
topic_type: true,
notify_type: true,
custom_type: true,
)
@flag_settings.add(10, :illegal, topic_type: true, notify_type: true, custom_type: true)
# When adding a new ID here, check that it doesn't clash with any added in
# `ReviewableScore.types`. You can thank me later.
end
end

reload_types
initialize_flag_settings
end

# == Schema Information
Expand Down
12 changes: 6 additions & 6 deletions app/serializers/post_action_type_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ def is_flag
end

def name
i18n("title", default: object.class.flag_settings.names[object.id])
i18n("title")
end

def description
i18n("description", vars: { tos_url: tos_url, base_path: Discourse.base_path })
i18n("description", tos_url: tos_url, base_path: Discourse.base_path)
end

def short_description
i18n("short_description", vars: { tos_url: tos_url, base_path: Discourse.base_path })
i18n("short_description", tos_url: tos_url, base_path: Discourse.base_path)
end

def name_key
PostActionType.types[object.id].to_s
PostActionType.types[object.id]
end

protected

def i18n(field, default: nil, vars: nil)
def i18n(field, vars = nil)
key = "post_action_types.#{name_key}.#{field}"
vars ? I18n.t(key, vars, default: default) : I18n.t(key, default: default)
vars ? I18n.t(key, vars) : I18n.t(key)
end
end
5 changes: 2 additions & 3 deletions app/serializers/reviewable_score_type_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ def type

# Allow us to share post action type translations for backwards compatibility
def title
I18n.t("post_action_types.#{type}.title", default: nil) ||
I18n.t("reviewable_score_types.#{type}.title", default: nil) ||
PostActionType.flag_settings.names[id]
I18n.t("post_action_types.#{ReviewableScore.types[id]}.title", default: nil) ||
I18n.t("reviewable_score_types.#{ReviewableScore.types[id]}.title")
end

def reviewable_priority
Expand Down
9 changes: 8 additions & 1 deletion app/serializers/site_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ def include_lazy_load_categories?
private

def ordered_flags(flags)
flags.map { |id| PostActionType.new(id: id) }
notify_moderators_type = PostActionType.flag_types[:notify_moderators]
types = flags

if notify_moderators_flag = types.index(notify_moderators_type)
types.insert(types.length, types.delete_at(notify_moderators_flag))
end

types.map { |id| PostActionType.new(id: id) }
end
end
4 changes: 2 additions & 2 deletions app/serializers/topic_flag_type_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class TopicFlagTypeSerializer < PostActionTypeSerializer
protected

def i18n(field, default: nil, vars: nil)
def i18n(field, vars = nil)
key = "topic_flag_types.#{name_key}.#{field}"
vars ? I18n.t(key, vars, default: default) : I18n.t(key, default: default)
vars ? I18n.t(key, vars) : I18n.t(key)
end
end
1 change: 0 additions & 1 deletion config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3748,7 +3748,6 @@ en:
illegal: "You flagged this as illegal"
notify_moderators: "You flagged this for moderation"
notify_user: "You sent a message to this user"
custom: "You flagged this topic as %{custom}"

delete:
confirm:
Expand Down
56 changes: 0 additions & 56 deletions db/fixtures/003_flags.rb

This file was deleted.

2 changes: 1 addition & 1 deletion db/migrate/20181031165343_add_flag_stats_to_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def up
SUM(CASE WHEN pa.deferred_at IS NOT NULL THEN 1 ELSE 0 END) as flags_ignored
FROM post_actions AS pa
INNER JOIN users AS u ON u.id = pa.user_id
WHERE pa.post_action_type_id IN (3, 4, 8, 7, 10)
WHERE pa.post_action_type_id IN (#{PostActionType.notify_flag_types.values.join(", ")})
AND pa.user_id > 0
GROUP BY u.id
) AS x
Expand Down
19 changes: 0 additions & 19 deletions db/migrate/20240423054323_create_flags.rb

This file was deleted.

25 changes: 7 additions & 18 deletions lib/flag_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class FlagSettings
:topic_flag_types,
:auto_action_types,
:custom_types,
:names,
)

def initialize
Expand All @@ -17,28 +16,18 @@ def initialize
@auto_action_types = Enum.new
@custom_types = Enum.new
@without_custom_types = Enum.new
@names = Enum.new
end

def add(
id,
name_key,
topic_type: nil,
notify_type: nil,
auto_action_type: nil,
custom_type: nil,
name: nil
)
@all_flag_types[name_key] = id
@topic_flag_types[name_key] = id if !!topic_type
@notify_types[name_key] = id if !!notify_type
@auto_action_types[name_key] = id if !!auto_action_type
@names[id] = name if name
def add(id, name, topic_type: nil, notify_type: nil, auto_action_type: nil, custom_type: nil)
@all_flag_types[name] = id
@topic_flag_types[name] = id if !!topic_type
@notify_types[name] = id if !!notify_type
@auto_action_types[name] = id if !!auto_action_type

if !!custom_type
@custom_types[name_key] = id
@custom_types[name] = id
else
@without_custom_types[name_key] = id
@without_custom_types[name] = id
end
end

Expand Down
2 changes: 0 additions & 2 deletions lib/guardian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require "guardian/category_guardian"
require "guardian/ensure_magic"
require "guardian/group_guardian"
require "guardian/flag_guardian"
require "guardian/post_guardian"
require "guardian/post_revision_guardian"
require "guardian/sidebar_guardian"
Expand All @@ -17,7 +16,6 @@ class Guardian
include BookmarkGuardian
include CategoryGuardian
include EnsureMagic
include FlagGuardian
include GroupGuardian
include PostGuardian
include PostRevisionGuardian
Expand Down
7 changes: 0 additions & 7 deletions lib/guardian/flag_guardian.rb

This file was deleted.

Loading

0 comments on commit dbd21e9

Please sign in to comment.