mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: move staff tags setting to tag group settings
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
import PermissionType from 'discourse/models/permission-type';
|
||||
|
||||
const TagGroup = RestModel.extend({
|
||||
@computed('name', 'tag_names')
|
||||
@@ -8,6 +9,31 @@ const TagGroup = RestModel.extend({
|
||||
return Ember.isEmpty(this.get('name')) || Ember.isEmpty(this.get('tag_names')) || this.get('saving');
|
||||
},
|
||||
|
||||
@computed('permissions')
|
||||
permissionName: {
|
||||
get(permissions) {
|
||||
if (!permissions) return 'public';
|
||||
|
||||
if (permissions['everyone'] === PermissionType.FULL) {
|
||||
return 'public';
|
||||
} else if (permissions['everyone'] === PermissionType.READONLY) {
|
||||
return 'visible';
|
||||
} else {
|
||||
return 'private';
|
||||
}
|
||||
},
|
||||
|
||||
set(value) {
|
||||
if (value === 'private') {
|
||||
this.set('permissions', {'staff': PermissionType.FULL});
|
||||
} else if (value === 'visible') {
|
||||
this.set('permissions', {'staff': PermissionType.FULL, 'everyone': PermissionType.READONLY});
|
||||
} else {
|
||||
this.set('permissions', {'everyone': PermissionType.FULL});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
save() {
|
||||
let url = "/tag_groups";
|
||||
const self = this,
|
||||
@@ -25,7 +51,7 @@ const TagGroup = RestModel.extend({
|
||||
tag_names: this.get('tag_names'),
|
||||
parent_tag_name: this.get('parent_tag_name') ? this.get('parent_tag_name') : undefined,
|
||||
one_per_topic: this.get('one_per_topic'),
|
||||
permissions: this.get('visible_only_to_staff') ? {"staff": "1"} : {"everyone": "1"}
|
||||
permissions: this.get('permissions')
|
||||
},
|
||||
type: isNew ? 'POST' : 'PUT'
|
||||
}).then(function(result) {
|
||||
|
||||
@@ -29,10 +29,18 @@
|
||||
</section>
|
||||
|
||||
<section class="group-visibility">
|
||||
<label>
|
||||
{{input type="checkbox" checked=model.visible_only_to_staff name="visible_only_to_staff"}}
|
||||
{{i18n 'tagging.groups.visible_only_to_staff'}}
|
||||
</label>
|
||||
<div>
|
||||
{{radio-button class="tag-permissions-choice" name="tag-permissions-choice" value="public" id="public-permission" selection=model.permissionName}}
|
||||
<label class="radio" for="public-permission">{{i18n 'tagging.groups.everyone_can_use'}}</label>
|
||||
</div>
|
||||
<div>
|
||||
{{radio-button class="tag-permissions-choice" name="tag-permissions-choice" value="visible" id="visible-permission" selection=model.permissionName}}
|
||||
<label class="radio" for="visible-permission">{{i18n 'tagging.groups.usable_only_by_staff'}}</label>
|
||||
</div>
|
||||
<div>
|
||||
{{radio-button class="tag-permissions-choice" name="tag-permissions-choice" value="private" id="private-permission" selection=model.permissionName}}
|
||||
<label class="radio" for="private-permission">{{i18n 'tagging.groups.visible_only_to_staff'}}</label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<button {{action "save"}} disabled={{model.disableSave}} class='btn'>{{i18n 'tagging.groups.save'}}</button>
|
||||
|
||||
@@ -237,6 +237,9 @@ header .discourse-tag {color: $tag-color }
|
||||
ul {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.btn {
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
.tag-group-content {
|
||||
width: 75%;
|
||||
@@ -249,11 +252,13 @@ header .discourse-tag {color: $tag-color }
|
||||
display: inline-block;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.btn {
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
.group-tags-list .tag-chooser {
|
||||
width: 100%;
|
||||
}
|
||||
.btn {margin-left: 10px;}
|
||||
.saving {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -255,8 +255,12 @@ class PostRevisionSerializer < ApplicationSerializer
|
||||
end
|
||||
|
||||
def filter_visible_tags(tags)
|
||||
@hidden_tag_names ||= DiscourseTagging.hidden_tag_names(scope)
|
||||
tags.is_a?(Array) ? (tags - @hidden_tag_names) : tags
|
||||
if tags.is_a?(Array) && tags.size > 0
|
||||
@hidden_tag_names ||= DiscourseTagging.hidden_tag_names(scope)
|
||||
tags - @hidden_tag_names
|
||||
else
|
||||
tags
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class TagGroupSerializer < ApplicationSerializer
|
||||
attributes :id, :name, :tag_names, :parent_tag_name, :one_per_topic, :visible_only_to_staff
|
||||
attributes :id, :name, :tag_names, :parent_tag_name, :one_per_topic, :permissions
|
||||
|
||||
def tag_names
|
||||
object.tags.map(&:name).sort
|
||||
@@ -8,4 +8,17 @@ class TagGroupSerializer < ApplicationSerializer
|
||||
def parent_tag_name
|
||||
[object.parent_tag.try(:name)].compact
|
||||
end
|
||||
|
||||
def permissions
|
||||
@permissions ||= begin
|
||||
h = {}
|
||||
object.tag_group_permissions.joins(:group).includes(:group).order("groups.name").each do |tgp|
|
||||
h[tgp.group.name] = tgp.permission_type
|
||||
end
|
||||
if h.size == 0
|
||||
h['everyone'] = TagGroupPermission.permission_types[:full]
|
||||
end
|
||||
h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user