using settings model correctly

pull/2361/head
Diego Sampaio 10 years ago
parent 265b8f3735
commit ea3adb7ff7
  1. 2
      packages/rocketchat-github-enterprise/common.coffee
  2. 2
      packages/rocketchat-gitlab/common.coffee
  3. 2
      packages/rocketchat-hubot/hubot.coffee
  4. 29
      packages/rocketchat-lib/server/models/Settings.coffee
  5. 12
      packages/rocketchat-lib/server/publications/settings.coffee

@ -13,7 +13,7 @@ GitHubEnterprise = new CustomOAuth 'github_enterprise', config
if Meteor.isServer
Meteor.startup ->
RocketChat.models.Settings.find({ _id: 'API_GitHub_Enterprise_URL' }).observe
RocketChat.models.Settings.findById('API_GitHub_Enterprise_URL').observe
added: (record) ->
config.serverURL = RocketChat.settings.get 'API_GitHub_Enterprise_URL'
GitHubEnterprise.configure config

@ -9,7 +9,7 @@ Gitlab = new CustomOAuth 'gitlab', config
if Meteor.isServer
Meteor.startup ->
RocketChat.models.Settings.find({ _id: 'API_Gitlab_URL' }).observe
RocketChat.models.Settings.findById('API_Gitlab_URL').observe
added: (record) ->
config.serverURL = RocketChat.settings.get 'API_Gitlab_URL'
Gitlab.configure config

@ -339,7 +339,7 @@ init = =>
# username: "rocketbot"
# action: true
RocketChat.models.Settings.find({ _id: { $in: [ 'RocketBot_Name', 'RocketBot_Enabled'] } }).observe
RocketChat.models.Settings.findByIds([ 'RocketBot_Name', 'RocketBot_Enabled']).observe
added: ->
init()
changed: ->

@ -2,6 +2,7 @@ RocketChat.models.Settings = new class extends RocketChat.models._Base
constructor: ->
@_initModel 'settings'
@tryEnsureIndex { 'hidden': 1 }, { sparse: 1 }
# FIND ONE
findOneById: (_id, options) ->
@ -12,6 +13,21 @@ RocketChat.models.Settings = new class extends RocketChat.models._Base
# FIND
findById: (_id) ->
query =
_id: _id
return @find query
findByIds: (_id = []) ->
_id = [].concat _id
query =
_id:
$in: _id
return @find query
findByRole: (role, options) ->
query =
role: role
@ -24,6 +40,19 @@ RocketChat.models.Settings = new class extends RocketChat.models._Base
return @find query, options
findNotHiddenPublic: (ids = [])->
filter =
hidden: { $ne: true }
public: true
if ids.length > 0
filter._id =
$in: ids
return @find filter, { fields: _id: 1, value: 1 }
findNotHidden: ->
return @find { hidden: { $ne: true } }
# UPDATE
updateValueById: (_id, value) ->

@ -1,20 +1,12 @@
Meteor.publish 'settings', (ids = []) ->
filter =
hidden: { $ne: true }
public: true
if ids.length > 0
filter._id =
$in: ids
return RocketChat.models.Settings.find filter, { fields: _id: 1, value: 1 }
return RocketChat.models.Settings.findNotHiddenPublic(ids)
Meteor.publish 'admin-settings', ->
unless @userId
return @ready()
if RocketChat.authz.hasPermission( @userId, 'view-privileged-setting')
return RocketChat.models.Settings.find({ hidden: { $ne: true } })
return RocketChat.models.Settings.findNotHidden()
else
return @ready()

Loading…
Cancel
Save