FEATURE: move staff tags setting to tag group settings

This commit is contained in:
Neil Lalonde
2018-04-20 15:34:23 -04:00
parent cfcdc4b420
commit 70f2c5d3fd
20 changed files with 211 additions and 73 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ class CategoryGroup < ActiveRecord::Base
delegate :name, to: :group, prefix: true
def self.permission_types
@permission_types ||= Enum.new(:full, :create_post, :readonly)
@permission_types ||= Enum.new(full: 1, create_post: 2, readonly: 3)
end
end
+1 -1
View File
@@ -49,7 +49,7 @@ class Tag < ActiveRecord::Base
return [] if scope_category_ids.empty?
filter_sql = guardian&.is_staff? ? '' : (' AND ' + DiscourseTagging.filter_visible_sql)
filter_sql = guardian&.is_staff? ? '' : " AND tags.id NOT IN (#{DiscourseTagging.hidden_tags_query.select(:id).to_sql})"
tag_names_with_counts = Tag.exec_sql <<~SQL
SELECT tags.name as tag_name, SUM(stats.topic_count) AS sum_topic_count
+23 -8
View File
@@ -9,6 +9,7 @@ class TagGroup < ActiveRecord::Base
belongs_to :parent_tag, class_name: 'Tag'
before_create :init_permissions
before_save :apply_permissions
attr_accessor :permissions
@@ -45,6 +46,15 @@ class TagGroup < ActiveRecord::Base
end
end
def init_permissions
unless tag_group_permissions.present? || @permissions
tag_group_permissions.build(
group_id: Group::AUTO_GROUPS[:everyone],
permission_type: TagGroupPermission.permission_types[:full]
)
end
end
def apply_permissions
if @permissions
tag_group_permissions.destroy_all
@@ -55,22 +65,27 @@ class TagGroup < ActiveRecord::Base
end
end
def visible_only_to_staff
# currently only "everyone" and "staff" groups are supported
tag_group_permissions.count > 0
end
def self.allowed(guardian)
if guardian.is_staff?
TagGroup
else
category_permissions_filter = <<~SQL
category_permissions_filter_sql = <<~SQL
(id IN ( SELECT tag_group_id FROM category_tag_groups WHERE category_id IN (?))
OR id NOT IN (SELECT tag_group_id FROM category_tag_groups))
AND id NOT IN (SELECT tag_group_id FROM tag_group_permissions)
AND id IN (
SELECT tag_group_id
FROM tag_group_permissions
WHERE group_id = ?
AND permission_type = ?
)
SQL
TagGroup.where(category_permissions_filter, guardian.allowed_category_ids)
TagGroup.where(
category_permissions_filter_sql,
guardian.allowed_category_ids,
Group::AUTO_GROUPS[:everyone],
TagGroupPermission.permission_types[:full]
)
end
end
end
+1 -1
View File
@@ -4,7 +4,7 @@ class TagGroupPermission < ActiveRecord::Base
belongs_to :group
def self.permission_types
@permission_types ||= Enum.new(full: 1) #, see: 2
@permission_types ||= Enum.new(full: 1, readonly: 3)
end
end