about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/lib/command_tag/command/account_tools.rb2
-rw-r--r--app/models/account_domain_permission.rb5
-rw-r--r--db/migrate/20200901035527_add_sticky_to_account_domain_permissions.rb7
-rw-r--r--db/schema.rb3
4 files changed, 13 insertions, 4 deletions
diff --git a/app/lib/command_tag/command/account_tools.rb b/app/lib/command_tag/command/account_tools.rb
index b433c32d4..8c8c74e68 100644
--- a/app/lib/command_tag/command/account_tools.rb
+++ b/app/lib/command_tag/command/account_tools.rb
@@ -56,7 +56,7 @@ module CommandTag::Command::AccountTools
         @account.user.settings.default_privacy = args[1]
       elsif args[1] == 'public'
         domains = args[2..-1].map { |domain| normalize_domain(domain) unless domain == '*' }.uniq.compact
-        @account.domain_permissions.where(domain: domains).destroy_all if domains.present?
+        @account.domain_permissions.where(domain: domains, sticky: false).destroy_all if domains.present?
       elsif args[1] != 'cc'
         args[2..-1].flat_map(&:split).uniq.each do |domain|
           domain = normalize_domain(domain) unless domain == '*'
diff --git a/app/models/account_domain_permission.rb b/app/models/account_domain_permission.rb
index 2606c4133..9e77950f2 100644
--- a/app/models/account_domain_permission.rb
+++ b/app/models/account_domain_permission.rb
@@ -7,6 +7,7 @@
 #  account_id :bigint(8)        not null
 #  domain     :string           default(""), not null
 #  visibility :integer          default("public"), not null
+#  sticky     :boolean          default(FALSE), not null
 #
 
 class AccountDomainPermission < ApplicationRecord
@@ -40,7 +41,7 @@ class AccountDomainPermission < ApplicationRecord
       domain_permissions = normalize(domain_permissions)
       permissions = find_by(domain: domain_permissions[:domain])
       if permissions.present?
-        permissions.update(**domain_permissions)
+        permissions.update(**domain_permissions) unless permissions.sticky? && %w(direct limited private).include?(domain_permissions[:visibility].to_s)
       else
         create(**domain_permissions)
       end
@@ -51,7 +52,7 @@ class AccountDomainPermission < ApplicationRecord
       domain_permissions = normalize(domain_permissions)
       permissions = find_by(domain: domain_permissions[:domain])
       if permissions.present?
-        permissions.update!(**domain_permissions)
+        permissions.update!(**domain_permissions) unless permissions.sticky? && %w(direct limited private).include?(domain_permissions[:visibility].to_s)
       else
         create!(**domain_permissions)
       end
diff --git a/db/migrate/20200901035527_add_sticky_to_account_domain_permissions.rb b/db/migrate/20200901035527_add_sticky_to_account_domain_permissions.rb
new file mode 100644
index 000000000..2acfce329
--- /dev/null
+++ b/db/migrate/20200901035527_add_sticky_to_account_domain_permissions.rb
@@ -0,0 +1,7 @@
+class AddStickyToAccountDomainPermissions < ActiveRecord::Migration[5.2]
+  def change
+    safety_assured do
+      add_column :account_domain_permissions, :sticky, :boolean, default: false, null: false
+    end
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 9ee9c345d..88105f462 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2020_08_26_125821) do
+ActiveRecord::Schema.define(version: 2020_09_01_035527) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -48,6 +48,7 @@ ActiveRecord::Schema.define(version: 2020_08_26_125821) do
     t.bigint "account_id", null: false
     t.string "domain", default: "", null: false
     t.integer "visibility", default: 0, null: false
+    t.boolean "sticky", default: false, null: false
     t.index ["account_id", "domain"], name: "index_account_domain_permissions_on_account_id_and_domain", unique: true
     t.index ["account_id"], name: "index_account_domain_permissions_on_account_id"
     t.index ["domain"], name: "index_account_domain_permissions_on_domain"