mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 11:13:22 +08:00
move alias levels into enums
This commit is contained in:
parent
c743a985a4
commit
7cbe92d5b6
|
@ -1,6 +1,15 @@
|
|||
Discourse.Group = Discourse.Model.extend({
|
||||
loaded: false,
|
||||
|
||||
|
||||
ALIAS_LEVELS : {
|
||||
"nobody": 0,
|
||||
"only_admins": 1,
|
||||
"mods_and_admins": 2,
|
||||
"members_mods_and_admins": 3,
|
||||
"everyone": 99
|
||||
},
|
||||
|
||||
userCountDisplay: function(){
|
||||
var c = this.get('user_count');
|
||||
// don't display zero its ugly
|
||||
|
@ -37,11 +46,11 @@ Discourse.Group = Discourse.Model.extend({
|
|||
|
||||
validValues: function() {
|
||||
return Em.A([
|
||||
{ name: I18n.t("admin.groups.alias_levels.nobody"), value: 0},
|
||||
{ name: I18n.t("admin.groups.alias_levels.only_admins"), value: 1},
|
||||
{ name: I18n.t("admin.groups.alias_levels.mods_and_admins"), value: 2},
|
||||
{ name: I18n.t("admin.groups.alias_levels.members_mods_and_admins"), value: 3},
|
||||
{ name: I18n.t("admin.groups.alias_levels.everyone"), value: 99}
|
||||
{ name: I18n.t("admin.groups.alias_levels.nobody"), value: this.ALIAS_LEVELS.nobody},
|
||||
{ name: I18n.t("admin.groups.alias_levels.only_admins"), value: this.ALIAS_LEVELS.only_admins},
|
||||
{ name: I18n.t("admin.groups.alias_levels.mods_and_admins"), value: this.ALIAS_LEVELS.mods_and_admins},
|
||||
{ name: I18n.t("admin.groups.alias_levels.members_mods_and_admins"), value: this.ALIAS_LEVELS.members_mods_and_admins},
|
||||
{ name: I18n.t("admin.groups.alias_levels.everyone"), value: this.ALIAS_LEVELS.everyone}
|
||||
]);
|
||||
}.property(),
|
||||
|
||||
|
|
|
@ -21,6 +21,16 @@ class Group < ActiveRecord::Base
|
|||
:trust_level_5 => 15
|
||||
}
|
||||
|
||||
ALIAS_LEVELS = {
|
||||
:nobody => 0,
|
||||
:only_admins => 1,
|
||||
:mods_and_admins => 2,
|
||||
:members_mods_and_admins => 3,
|
||||
:everyone => 99
|
||||
}
|
||||
|
||||
validate :alias_level, inclusion: { in: ALIAS_LEVELS.values}
|
||||
|
||||
def self.trust_group_ids
|
||||
(10..19).to_a
|
||||
end
|
||||
|
@ -101,16 +111,21 @@ class Group < ActiveRecord::Base
|
|||
|
||||
def self.search_group(name, current_user)
|
||||
|
||||
levels = [99]
|
||||
levels = [ALIAS_LEVELS[:everyone]]
|
||||
if current_user.admin?
|
||||
levels = [99, 1, 2, 3]
|
||||
levels = [ALIAS_LEVELS[:everyone],
|
||||
ALIAS_LEVELS[:only_admins],
|
||||
ALIAS_LEVELS[:mods_and_admins],
|
||||
ALIAS_LEVELS[:members_mods_and_admins]]
|
||||
elsif current_user.moderator?
|
||||
levels = [99, 2, 3]
|
||||
levels = [ALIAS_LEVELS[:everyone],
|
||||
ALIAS_LEVELS[:mods_and_admins],
|
||||
ALIAS_LEVELS[:members_mods_and_admins]]
|
||||
end
|
||||
|
||||
return Group.where("name LIKE :term_like AND (" +
|
||||
" alias_level in (:levels)" +
|
||||
" OR (alias_level = 3 AND id in (" +
|
||||
" OR (alias_level = #{ALIAS_LEVELS[:everyone]} AND id in (" +
|
||||
"SELECT group_id FROM group_users WHERE user_id= :user_id)" +
|
||||
")" +
|
||||
")", term_like: "#{name.downcase}%", levels: levels, user_id: current_user.id)
|
||||
|
|
Loading…
Reference in New Issue
Block a user