Skip to content

Commit

Permalink
DEV: Scope topic voting tables to avoid confusion with post voting (#196
Browse files Browse the repository at this point in the history
)

Renaming discourse_voting to topic_voting since there are two forms of voting in Discourse - posts and topics.

This PR also moves a OnceOff into a post migration. The post migration will be executed, but should ideally be a no-op. This allows us to not have to maintain the OnceOff as it had to be modified before with a previous migration. I considered removing this file altogether, but I don't think there is anything negative from just converting it into a migration, and it might be useful in the unlikely scenario that a forum from the past has never ran the OnceOff before.
  • Loading branch information
nattsw authored Jul 17, 2024
1 parent fdb1f98 commit 3d30377
Show file tree
Hide file tree
Showing 76 changed files with 608 additions and 519 deletions.
1 change: 1 addition & 0 deletions .discourse-compatibility
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
< 3.3.0.beta5-dev: fdb1f98a963adac049ffe9cd4fc506d77dd38cca
< 3.3.0.beta1-dev: ba41633e0abe0535fd358a0809e0b4e0c79be128
< 3.2.0.beta2-dev: ca2449f243ba3de5182fead8c66c2346cd25ed2c
3.1.999: 6449fc15658d972e20086a3f1fae3dbac9cd9eeb
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/discourse_topic_voting/votes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def unvote
protected

def who_voted(topic)
return nil unless SiteSetting.voting_show_who_voted
return nil unless SiteSetting.topic_voting_show_who_voted

ActiveModel::ArraySerializer.new(
topic.who_voted,
Expand Down
94 changes: 0 additions & 94 deletions app/jobs/onceoff/voting_ensure_consistency.rb

This file was deleted.

14 changes: 7 additions & 7 deletions app/models/discourse_topic_voting/category_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module DiscourseTopicVoting
class CategorySetting < ActiveRecord::Base
self.table_name = "discourse_voting_category_settings"
self.table_name = "topic_voting_category_settings"

belongs_to :category, inverse_of: :discourse_topic_voting_category_setting

Expand All @@ -12,24 +12,24 @@ class CategorySetting < ActiveRecord::Base

def unarchive_votes
DB.exec(<<~SQL, { category_id: self.category_id })
UPDATE discourse_voting_votes
UPDATE topic_voting_votes
SET archive=false
FROM topics
WHERE topics.category_id = :category_id
AND topics.deleted_at is NULL
AND NOT topics.closed
AND NOT topics.archived
AND discourse_voting_votes.topic_id = topics.id
AND topic_voting_votes.topic_id = topics.id
SQL
end

def archive_votes
DB.exec(<<~SQL, { category_id: self.category_id })
UPDATE discourse_voting_votes
UPDATE topic_voting_votes
SET archive=true
FROM topics
WHERE topics.category_id = :category_id
AND discourse_voting_votes.topic_id = topics.id
AND topic_voting_votes.topic_id = topics.id
SQL
end

Expand All @@ -41,7 +41,7 @@ def reset_voting_cache

# == Schema Information
#
# Table name: discourse_voting_category_settings
# Table name: topic_voting_category_settings
#
# id :bigint not null, primary key
# category_id :integer
Expand All @@ -50,5 +50,5 @@ def reset_voting_cache
#
# Indexes
#
# index_discourse_voting_category_settings_on_category_id (category_id) UNIQUE
# index_topic_voting_category_settings_on_category_id (category_id) UNIQUE
#
6 changes: 3 additions & 3 deletions app/models/discourse_topic_voting/topic_vote_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

module DiscourseTopicVoting
class TopicVoteCount < ActiveRecord::Base
self.table_name = "discourse_voting_topic_vote_count"
self.table_name = "topic_voting_topic_vote_count"

belongs_to :topic
end
end

# == Schema Information
#
# Table name: discourse_voting_topic_vote_count
# Table name: topic_voting_topic_vote_count
#
# id :bigint not null, primary key
# topic_id :integer
Expand All @@ -20,5 +20,5 @@ class TopicVoteCount < ActiveRecord::Base
#
# Indexes
#
# index_discourse_voting_topic_vote_count_on_topic_id (topic_id) UNIQUE
# index_topic_voting_topic_vote_count_on_topic_id (topic_id) UNIQUE
#
6 changes: 3 additions & 3 deletions app/models/discourse_topic_voting/vote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module DiscourseTopicVoting
class Vote < ActiveRecord::Base
self.table_name = "discourse_voting_votes"
self.table_name = "topic_voting_votes"

belongs_to :user
belongs_to :topic
Expand All @@ -11,7 +11,7 @@ class Vote < ActiveRecord::Base

# == Schema Information
#
# Table name: discourse_voting_votes
# Table name: topic_voting_votes
#
# id :bigint not null, primary key
# topic_id :integer
Expand All @@ -22,5 +22,5 @@ class Vote < ActiveRecord::Base
#
# Indexes
#
# index_discourse_voting_votes_on_user_id_and_topic_id (user_id,topic_id) UNIQUE
# index_topic_voting_votes_on_user_id_and_topic_id (user_id,topic_id) UNIQUE
#
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
initialize() {
withPluginApi("0.8.32", (api) => {
const siteSettings = api.container.lookup("service:site-settings");
if (siteSettings.voting_enabled) {
if (siteSettings.topic_voting_enabled) {
const pageSearchController = api.container.lookup(
"controller:full-page-search"
);
Expand Down Expand Up @@ -61,7 +61,7 @@ export default {

withPluginApi("0.11.7", (api) => {
const siteSettings = api.container.lookup("service:site-settings");
if (siteSettings.voting_enabled) {
if (siteSettings.topic_voting_enabled) {
api.addSearchSuggestion("order:votes");
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#if siteSettings.voting_show_votes_on_profile}}
{{#if siteSettings.topic_voting_show_votes_on_profile}}
<LinkTo @route="userActivity.votes">
{{d-icon "heart"}}
{{i18n "topic_voting.vote_title_plural"}}
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/discourse/widgets/vote-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default createWidget("vote-box", {
buildKey: () => "vote-box",

buildClasses() {
if (this.siteSettings.voting_show_who_voted) {
if (this.siteSettings.topic_voting_show_who_voted) {
return "show-pointer";
}
},
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/discourse/widgets/vote-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default createWidget("vote-button", {
}
}
}
if (this.siteSettings.voting_show_who_voted) {
if (this.siteSettings.topic_voting_show_who_voted) {
buttonClass += " show-pointer";
}
return buttonClass;
Expand Down
7 changes: 5 additions & 2 deletions assets/javascripts/discourse/widgets/vote-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default createWidget("vote-count", {
let voteCount = h("div.vote-count", attrs.vote_count.toString());
let whoVoted = null;
if (
this.siteSettings.voting_show_who_voted &&
this.siteSettings.topic_voting_show_who_voted &&
this.state.whoVotedUsers &&
this.state.whoVotedUsers.length > 0
) {
Expand All @@ -47,7 +47,10 @@ export default createWidget("vote-count", {
return;
}

if (this.siteSettings.voting_show_who_voted && this.attrs.vote_count > 0) {
if (
this.siteSettings.topic_voting_show_who_voted &&
this.attrs.vote_count > 0
) {
if (this.state.whoVotedUsers === null) {
return this.getWhoVoted();
} else {
Expand Down
18 changes: 9 additions & 9 deletions config/locales/server.ar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

ar:
site_settings:
voting_enabled: 'السماح للأعضاء بالتصويت على الموضوعات؟'
voting_tl0_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 0؟'
voting_tl1_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 1؟'
voting_tl2_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 2؟'
voting_tl3_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 3؟'
voting_tl4_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 4؟'
voting_show_who_voted: 'هل تريد السماح للأعضاء برؤية من صوَّتوا؟'
voting_show_votes_on_profile: 'هل تريد السماح للأعضاء برؤية أصواتهم في موجز النشاط؟'
voting_alert_votes_left: 'تنبيه المستخدم عندما يتبقى هذا العدد من الأصوات'
topic_voting_enabled: 'السماح للأعضاء بالتصويت على الموضوعات؟'
topic_voting_tl0_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 0؟'
topic_voting_tl1_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 1؟'
topic_voting_tl2_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 2؟'
topic_voting_tl3_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 3؟'
topic_voting_tl4_vote_limit: 'ما عدد الأصوات النشطة المسموح بها للمستخدمين من مستوى الثقة 4؟'
topic_voting_show_who_voted: 'هل تريد السماح للأعضاء برؤية من صوَّتوا؟'
topic_voting_show_votes_on_profile: 'هل تريد السماح للأعضاء برؤية أصواتهم في موجز النشاط؟'
topic_voting_alert_votes_left: 'تنبيه المستخدم عندما يتبقى هذا العدد من الأصوات'
topic_voting:
votes_moved:
zero: "تم نقل %{count} صوت."
Expand Down
18 changes: 9 additions & 9 deletions config/locales/server.bg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

bg:
site_settings:
voting_enabled: 'Да се разреши ли на потребителите да гласуват по теми?'
voting_tl0_vote_limit: 'Колко активни гласа са позволени на потребителите на TL0?'
voting_tl1_vote_limit: 'Колко активни гласа са позволени на потребителите на TL1?'
voting_tl2_vote_limit: 'Колко активни гласа са позволени на потребителите на TL2?'
voting_tl3_vote_limit: 'Колко активни гласа са позволени на потребителите на TL3?'
voting_tl4_vote_limit: 'Колко активни гласа са позволени на потребителите на TL4?'
voting_show_who_voted: 'Позволяване ли на потребителите да видят кой е гласувал?'
voting_show_votes_on_profile: 'Позволяване на потребителите да виждат своите гласове в потока на активността си?'
voting_alert_votes_left: 'Уведомете потребителя, когато останат толкова гласове'
topic_voting_enabled: 'Да се разреши ли на потребителите да гласуват по теми?'
topic_voting_tl0_vote_limit: 'Колко активни гласа са позволени на потребителите на TL0?'
topic_voting_tl1_vote_limit: 'Колко активни гласа са позволени на потребителите на TL1?'
topic_voting_tl2_vote_limit: 'Колко активни гласа са позволени на потребителите на TL2?'
topic_voting_tl3_vote_limit: 'Колко активни гласа са позволени на потребителите на TL3?'
topic_voting_tl4_vote_limit: 'Колко активни гласа са позволени на потребителите на TL4?'
topic_voting_show_who_voted: 'Позволяване ли на потребителите да видят кой е гласувал?'
topic_voting_show_votes_on_profile: 'Позволяване на потребителите да виждат своите гласове в потока на активността си?'
topic_voting_alert_votes_left: 'Уведомете потребителя, когато останат толкова гласове'
topic_voting:
votes_moved:
one: "Един глас беше преместен."
Expand Down
18 changes: 9 additions & 9 deletions config/locales/server.bs_BA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

bs_BA:
site_settings:
voting_enabled: 'Dozvoli korisnicima da glasaju u temama?'
voting_tl0_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 0?'
voting_tl1_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 1?'
voting_tl2_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 2?'
voting_tl3_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 3?'
voting_tl4_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 4?'
voting_show_who_voted: 'Dozvoli korisnicima da vide ko je glasao?'
voting_show_votes_on_profile: 'Dozvoli korisnicima da vide svoje glasove u svojem pregledu aktivnosti?'
voting_alert_votes_left: 'Upozorite korisnike kada do naksimalnog broja glasova ostano još'
topic_voting_enabled: 'Dozvoli korisnicima da glasaju u temama?'
topic_voting_tl0_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 0?'
topic_voting_tl1_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 1?'
topic_voting_tl2_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 2?'
topic_voting_tl3_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 3?'
topic_voting_tl4_vote_limit: 'Koliko aktivnih glasova je dozvoljeno korisnicima sa nivoom povjerenja 4?'
topic_voting_show_who_voted: 'Dozvoli korisnicima da vide ko je glasao?'
topic_voting_show_votes_on_profile: 'Dozvoli korisnicima da vide svoje glasove u svojem pregledu aktivnosti?'
topic_voting_alert_votes_left: 'Upozorite korisnike kada do naksimalnog broja glasova ostano još'
topic_voting:
votes_moved:
one: "Glas je maknut."
Expand Down
18 changes: 9 additions & 9 deletions config/locales/server.ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

ca:
site_settings:
voting_enabled: 'Voleu permetre als usuaris votar sobre temes?'
voting_tl0_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 0?'
voting_tl1_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 1?'
voting_tl2_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 2?'
voting_tl3_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 3?'
voting_tl4_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 4?'
voting_show_who_voted: 'Voleu permetre que els usuaris vegin qui ha votat?'
voting_show_votes_on_profile: 'Voleu permetre als usuaris veure els seus vots en el seu canal d''activitat?'
voting_alert_votes_left: 'Alerta l''usuari quan quedi aquesta quantitat de vots'
topic_voting_enabled: 'Voleu permetre als usuaris votar sobre temes?'
topic_voting_tl0_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 0?'
topic_voting_tl1_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 1?'
topic_voting_tl2_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 2?'
topic_voting_tl3_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 3?'
topic_voting_tl4_vote_limit: 'Quants vots actius són permesos als usuaris del nivell de confiança 4?'
topic_voting_show_who_voted: 'Voleu permetre que els usuaris vegin qui ha votat?'
topic_voting_show_votes_on_profile: 'Voleu permetre als usuaris veure els seus vots en el seu canal d''activitat?'
topic_voting_alert_votes_left: 'Alerta l''usuari quan quedi aquesta quantitat de vots'
topic_voting:
votes_moved:
one: "S'ha mogut un vot"
Expand Down
Loading

0 comments on commit 3d30377

Please sign in to comment.