Skip to content
Snippets Groups Projects
Commit ea3adb7f authored by Diego Sampaio's avatar Diego Sampaio
Browse files

using settings model correctly

parent 265b8f37
No related merge requests found
...@@ -13,7 +13,7 @@ GitHubEnterprise = new CustomOAuth 'github_enterprise', config ...@@ -13,7 +13,7 @@ GitHubEnterprise = new CustomOAuth 'github_enterprise', config
if Meteor.isServer if Meteor.isServer
Meteor.startup -> Meteor.startup ->
RocketChat.models.Settings.find({ _id: 'API_GitHub_Enterprise_URL' }).observe RocketChat.models.Settings.findById('API_GitHub_Enterprise_URL').observe
added: (record) -> added: (record) ->
config.serverURL = RocketChat.settings.get 'API_GitHub_Enterprise_URL' config.serverURL = RocketChat.settings.get 'API_GitHub_Enterprise_URL'
GitHubEnterprise.configure config GitHubEnterprise.configure config
......
...@@ -9,7 +9,7 @@ Gitlab = new CustomOAuth 'gitlab', config ...@@ -9,7 +9,7 @@ Gitlab = new CustomOAuth 'gitlab', config
if Meteor.isServer if Meteor.isServer
Meteor.startup -> Meteor.startup ->
RocketChat.models.Settings.find({ _id: 'API_Gitlab_URL' }).observe RocketChat.models.Settings.findById('API_Gitlab_URL').observe
added: (record) -> added: (record) ->
config.serverURL = RocketChat.settings.get 'API_Gitlab_URL' config.serverURL = RocketChat.settings.get 'API_Gitlab_URL'
Gitlab.configure config Gitlab.configure config
......
...@@ -339,7 +339,7 @@ init = => ...@@ -339,7 +339,7 @@ init = =>
# username: "rocketbot" # username: "rocketbot"
# action: true # action: true
RocketChat.models.Settings.find({ _id: { $in: [ 'RocketBot_Name', 'RocketBot_Enabled'] } }).observe RocketChat.models.Settings.findByIds([ 'RocketBot_Name', 'RocketBot_Enabled']).observe
added: -> added: ->
init() init()
changed: -> changed: ->
......
...@@ -2,6 +2,7 @@ RocketChat.models.Settings = new class extends RocketChat.models._Base ...@@ -2,6 +2,7 @@ RocketChat.models.Settings = new class extends RocketChat.models._Base
constructor: -> constructor: ->
@_initModel 'settings' @_initModel 'settings'
@tryEnsureIndex { 'hidden': 1 }, { sparse: 1 }
# FIND ONE # FIND ONE
findOneById: (_id, options) -> findOneById: (_id, options) ->
...@@ -12,6 +13,21 @@ RocketChat.models.Settings = new class extends RocketChat.models._Base ...@@ -12,6 +13,21 @@ RocketChat.models.Settings = new class extends RocketChat.models._Base
# FIND # FIND
findById: (_id) ->
query =
_id: _id
return @find query
findByIds: (_id = []) ->
_id = [].concat _id
query =
_id:
$in: _id
return @find query
findByRole: (role, options) -> findByRole: (role, options) ->
query = query =
role: role role: role
...@@ -24,6 +40,19 @@ RocketChat.models.Settings = new class extends RocketChat.models._Base ...@@ -24,6 +40,19 @@ RocketChat.models.Settings = new class extends RocketChat.models._Base
return @find query, options 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 # UPDATE
updateValueById: (_id, value) -> updateValueById: (_id, value) ->
......
Meteor.publish 'settings', (ids = []) -> Meteor.publish 'settings', (ids = []) ->
filter = return RocketChat.models.Settings.findNotHiddenPublic(ids)
hidden: { $ne: true }
public: true
if ids.length > 0
filter._id =
$in: ids
return RocketChat.models.Settings.find filter, { fields: _id: 1, value: 1 }
Meteor.publish 'admin-settings', -> Meteor.publish 'admin-settings', ->
unless @userId unless @userId
return @ready() return @ready()
if RocketChat.authz.hasPermission( @userId, 'view-privileged-setting') if RocketChat.authz.hasPermission( @userId, 'view-privileged-setting')
return RocketChat.models.Settings.find({ hidden: { $ne: true } }) return RocketChat.models.Settings.findNotHidden()
else else
return @ready() return @ready()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment