Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Collections by Models #822

Merged
merged 51 commits into from
Sep 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
e56c223
Replace all Meteor.users.findOne
rodrigok Sep 15, 2015
d82d02d
Rename onlineUsers to filteredUsers
rodrigok Sep 15, 2015
a10054e
Replace all Meteor.users.find
rodrigok Sep 15, 2015
9bf7b78
Merge remote-tracking branch 'origin/master' into models
rodrigok Sep 16, 2015
7724b20
Replace all Meteor.users.update
rodrigok Sep 16, 2015
3c67377
Replace all Meteor.users.insert
rodrigok Sep 16, 2015
f17ea17
Replace all Meteor.users.remove
rodrigok Sep 16, 2015
599c650
Merge branch 'master' into models
rodrigok Sep 16, 2015
e03e929
Replace all ChatSubscriptions.find and update
rodrigok Sep 16, 2015
12ef1b4
Replace all Subscription.insert
rodrigok Sep 16, 2015
647312a
Replace all ChatSubscription.remove
rodrigok Sep 16, 2015
2314808
Implement methods to handle indexes in Models
rodrigok Sep 16, 2015
c8f6e15
Replace index commands from ChatSubscription
rodrigok Sep 16, 2015
0987f6a
Replace all ChatSubscription.upsert
rodrigok Sep 16, 2015
fddb27a
Remove all referentes to ChatSubscription at server side
rodrigok Sep 16, 2015
8370539
Replace ChatSubscription from packages
rodrigok Sep 16, 2015
e2fb798
Add Subscriptions.coffee to core package
rodrigok Sep 16, 2015
cb7a045
Merge remote-tracking branch 'origin/master' into models
rodrigok Sep 17, 2015
d7f7898
Replace all ChatRoom.findOne
rodrigok Sep 17, 2015
bfadb88
Replace all ChatRooms.find
rodrigok Sep 17, 2015
c359c3b
Replace all ChatRoom.remove
rodrigok Sep 17, 2015
8339c99
Replace all ChatRoom.upsert
rodrigok Sep 17, 2015
cc12274
Replace all ChatRoom.update
rodrigok Sep 18, 2015
eafaabc
Replace all ChatRoom.insert
rodrigok Sep 18, 2015
2beff30
Fix some mistakes and remove all references for ChatRoom
rodrigok Sep 18, 2015
bb65dd5
Merge remote-tracking branch 'origin/master' into models
rodrigok Sep 18, 2015
8dedb22
Replace all ChatMessage.findOne
rodrigok Sep 18, 2015
001fdb2
Replace all ChatMessage._ensureIndex and _dropIndex
rodrigok Sep 18, 2015
263c0d1
Replace all ChatMessage.find
rodrigok Sep 18, 2015
02e10ff
Fix some errors
rodrigok Sep 18, 2015
271233b
Replace all ChatMessage.remove
rodrigok Sep 19, 2015
3a664a9
Replace part of ChatMessage.insert
rodrigok Sep 19, 2015
df2f6bb
Replace ChatMessage in mingrations
rodrigok Sep 19, 2015
47db1cb
Merge remote-tracking branch 'origin/master' into models
rodrigok Sep 21, 2015
ef42cad
Replace all ChatMessage.insert
rodrigok Sep 21, 2015
9570d6f
Replace all ChatMessage.upsert
rodrigok Sep 21, 2015
6e97e2b
Merge remote-tracking branch 'origin/master' into models
rodrigok Sep 22, 2015
831bfd8
Replace all ChatMessage.update
rodrigok Sep 22, 2015
306eaab
Remove comment
rodrigok Sep 22, 2015
7cb07d2
Replace all MapReducedStatistics
rodrigok Sep 22, 2015
e1597e6
Remove comments
rodrigok Sep 22, 2015
abe1cd3
Replace all ChatReports
rodrigok Sep 22, 2015
e4be2e4
Replace all OEmbed.cache
rodrigok Sep 22, 2015
b4024e6
Replace "new Meteor.Collection" by @_initModel in models
rodrigok Sep 22, 2015
fa26d74
Replace all Statistics
rodrigok Sep 22, 2015
9346f25
Fix spelling
rodrigok Sep 22, 2015
535684b
Replace all ChatPermissions
rodrigok Sep 22, 2015
9e929f2
Fix packge file location
rodrigok Sep 22, 2015
aae6806
Replace all Settings
rodrigok Sep 22, 2015
4372a4c
Fix error with model Permissions
rodrigok Sep 22, 2015
b8b74fe
Merge remote-tracking branch 'origin/master' into models
rodrigok Sep 22, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/views/app/messagePopupConfig.coffee
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
@onlineUsers = new Mongo.Collection 'online-users'
@filteredUsers = new Mongo.Collection 'filtered-users'

Template.messagePopupConfig.helpers
popupUserConfig: ->
self = this
template = Template.instance()
config =
title: 'People'
collection: onlineUsers
collection: filteredUsers
template: 'messagePopupUser'
getInput: self.getInput
textFilterDelay: 200
getFilter: (collection, filter) ->
exp = new RegExp("^#{filter}", 'i')
Meteor.subscribe 'onlineUsers', filter
items = onlineUsers.find({$or: [{username: exp}, {name: exp}]}, {limit: 5}).fetch()
Meteor.subscribe 'filteredUsers', filter
items = filteredUsers.find({$or: [{username: exp}, {name: exp}]}, {limit: 5}).fetch()

all =
_id: '@all'
Expand Down
22 changes: 11 additions & 11 deletions packages/meteor-accounts-saml/saml_rocketchat.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ updateServices = ->
Meteor.clearTimeout timer if timer?

timer = Meteor.setTimeout ->
services = Settings.find({_id: /^(SAML_Custom_)[a-z]+$/i}).fetch()
services = RocketChat.models.Settings.find({_id: /^(SAML_Custom_)[a-z]+$/i}).fetch()

Accounts.saml.settings.providers = []

Expand All @@ -27,26 +27,26 @@ updateServices = ->

if service.value is true
data =
buttonLabelText: Settings.findOne({_id: "#{service._id}_button_label_text"})?.value
buttonLabelColor: Settings.findOne({_id: "#{service._id}_button_label_color"})?.value
buttonColor: Settings.findOne({_id: "#{service._id}_button_color"})?.value
buttonLabelText: RocketChat.models.Settings.findOneById("#{service._id}_button_label_text")?.value
buttonLabelColor: RocketChat.models.Settings.findOneById("#{service._id}_button_label_color")?.value
buttonColor: RocketChat.models.Settings.findOneById("#{service._id}_button_color")?.value
clientConfig:
provider: Settings.findOne({_id: "#{service._id}_provider"})?.value
provider: RocketChat.models.Settings.findOneById("#{service._id}_provider")?.value

Accounts.saml.settings.generateUsername = Settings.findOne({_id: "#{service._id}_generate_username"})?.value
Accounts.saml.settings.generateUsername = RocketChat.models.Settings.findOneById("#{service._id}_generate_username")?.value

Accounts.saml.settings.providers.push
provider: data.clientConfig.provider
entryPoint: Settings.findOne({_id: "#{service._id}_entry_point"})?.value
issuer: Settings.findOne({_id: "#{service._id}_issuer"})?.value
cert: Settings.findOne({_id: "#{service._id}_cert"})?.value
entryPoint: RocketChat.models.Settings.findOneById("#{service._id}_entry_point")?.value
issuer: RocketChat.models.Settings.findOneById("#{service._id}_issuer")?.value
cert: RocketChat.models.Settings.findOneById("#{service._id}_cert")?.value

ServiceConfiguration.configurations.upsert {service: serviceName.toLowerCase()}, $set: data
else
ServiceConfiguration.configurations.remove {service: serviceName.toLowerCase()}
, 2000

Settings.find().observe
RocketChat.models.Settings.find().observe
added: (record) ->
if /^SAML_.+/.test record._id
updateServices()
Expand All @@ -60,5 +60,5 @@ Settings.find().observe
updateServices()

Meteor.startup ->
if not Settings.findOne({_id: /^(SAML_Custom)[a-z]+$/i})?
if not RocketChat.models.Settings.findOne({_id: /^(SAML_Custom)[a-z]+$/i})?
Meteor.call 'addSamlService', 'default'
4 changes: 3 additions & 1 deletion packages/rocketchat-authorization/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ Package.onUse(function(api) {

api.use('templating', 'client');

api.addFiles('lib/permissions.coffee', ['server', 'client']);
api.addFiles('lib/rocketchat.coffee', ['server','client']);
api.addFiles('client/collection.coffee', ['client']);
api.addFiles('client/startup.coffee', ['client']);
api.addFiles('client/hasPermission.coffee', ['client']);
api.addFiles('client/hasRole.coffee', ['client']);


api.addFiles('server/models/Permissions.coffee', ['server']);

api.addFiles('server/functions/addUsersToRoles.coffee', ['server']);
api.addFiles('server/functions/getPermissionsForRole.coffee', ['server']);
api.addFiles('server/functions/getRoles.coffee', ['server']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RocketChat.authz.getPermissionsForRole = (roleName) ->
unless roleName in roleNames
throw new Meteor.Error 'invalid-role'

return _.pluck(ChatPermissions.find({roles : roleName }).fetch(), '_id')
return _.pluck(RocketChat.models.Permissions.findByRole( roleName ).fetch(), '_id')
11 changes: 11 additions & 0 deletions packages/rocketchat-authorization/server/models/Permissions.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RocketChat.models.Permissions = new class extends RocketChat.models._Base
constructor: ->
@_initModel 'permissions'


# FIND
findByRole: (role, options) ->
query =
roles: role

return @find query, options
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Meteor.publish 'permissions', ->
console.log '[publish] permissions'.green
return ChatPermissions.find {}
return RocketChat.models.Permissions.find {}
2 changes: 1 addition & 1 deletion packages/rocketchat-authorization/server/startup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Meteor.startup ->
roles = _.pluck(Roles.getAllRoles().fetch(), 'name');

for permission in permissions
ChatPermissions.upsert( permission._id, {$setOnInsert : permission })
RocketChat.models.Permissions.upsert( permission._id, {$setOnInsert : permission })
for role in permission.roles
unless role in roles
Roles.createRole role
Expand Down
50 changes: 16 additions & 34 deletions packages/rocketchat-irc/irc.server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class IrcClient
console.log '[irc] onReceiveMessage -> '.yellow, 'source:', source, 'target:', target, 'content:', content
source = @createUserWhenNotExist source
if target[0] == '#'
room = ChatRoom.findOne {name: target.substring 1}
room = RocketChat.models.Rooms.findOneByName target.substring(1)
else
room = @createDirectRoomWhenNotExist(source, @user)

Expand All @@ -178,7 +178,7 @@ class IrcClient
onEndMemberList: (roomName) ->
newMembers = @receiveMemberListBuf[roomName]
console.log '[irc] onEndMemberList -> '.yellow, 'room:', roomName, 'members:', newMembers.join ','
room = ChatRoom.findOne {name: roomName, t: 'c'}
room = RocketChat.models.Rooms.findOneByNameAndType roomName, 'c'
unless room
return

Expand All @@ -189,17 +189,9 @@ class IrcClient
for member in appendMembers
@createUserWhenNotExist member

update =
$pull:
usernames:
$in: removeMembers
ChatRoom.update room._id, update
update =
$addToSet:
usernames:
$each: appendMembers

ChatRoom.update room._id, update
RocketChat.models.Rooms.removeUsernamesById room._id, removeMembers
RocketChat.models.Rooms.addUsernamesById room._id, appendMembers

@isJoiningRoom = false
roomName = @pendingJoinRoomBuf.shift()
if roomName
Expand Down Expand Up @@ -231,15 +223,12 @@ class IrcClient
msg = "PRIVMSG #{target} :#{message.msg}\r\n"
@sendRawMessage msg

initRoomList: () ->
roomsCursor = ChatRoom.find
usernames:
$in: [@user.username]
t: 'c'
,
initRoomList: ->
roomsCursor = RocketChat.models.Rooms.findByTypeContainigUsername 'c', @user.username,
fields:
name: 1
t: 1

rooms = roomsCursor.fetch()
for room in rooms
@joinRoom(room)
Expand Down Expand Up @@ -276,25 +265,17 @@ class IrcClient

console.log '[irc] onAddMemberToRoom -> '.yellow, 'roomName:', roomName, 'member:', member
@createUserWhenNotExist member
update =
$addToSet:
usernames: member

ChatRoom.update {name: roomName}, update
RocketChat.models.Rooms.addUsernameByName roomName, member

onRemoveMemberFromRoom: (member, roomName)->
console.log '[irc] onRemoveMemberFromRoom -> '.yellow, 'roomName:', roomName, 'member:', member
update =
$pull:
usernames: member
ChatRoom.update {name: roomName}, update
RocketChat.models.Rooms.removeUsernameByName roomName, member

onQuiteMember: (member) ->
console.log '[irc] onQuiteMember ->'.yellow, 'username:', member
update =
$pull:
usernames: member
ChatRoom.update {}, update, {multi: true}
RocketChat.models.Rooms.removeUsernameFromAll member

Meteor.users.update {name: member},
$set:
status: 'offline'
Expand All @@ -319,7 +300,7 @@ class IrcClient
console.log '[irc] createDirectRoomWhenNotExist -> '.yellow, 'source:', source, 'target:', target
rid = [source._id, target._id].sort().join('')
now = new Date()
ChatRoom.upsert
RocketChat.models.Rooms.upsert
_id: rid
,
$set:
Expand All @@ -328,7 +309,8 @@ class IrcClient
t: 'd'
msgs: 0
ts: now
ChatSubscription.upsert

RocketChat.models.Subscriptions.upsert
rid: rid
$and: [{'u._id': target._id}]
,
Expand Down Expand Up @@ -373,7 +355,7 @@ class IrcSender
if ircReceiveMessageCache.get cacheKey
return message

room = ChatRoom.findOne message.rid, { fields: { name: 1, usernames: 1, t: 1 } }
room = RocketChat.models.Rooms.findOneById message.rid, { fields: { name: 1, usernames: 1, t: 1 } }
ircClient = IrcClient.getByUid message.u._id
ircClient.sendMessage room, message
return message
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-ldap/config_server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ updateServices = ->
Meteor.clearTimeout timer if timer?

timer = Meteor.setTimeout ->
enable = Settings.findOne({_id: 'LDAP_Enable', value: true})
enable = RocketChat.models.Settings.findOne({_id: 'LDAP_Enable', value: true})

if enable?
console.log "Enabling LDAP".blue
Expand All @@ -29,7 +29,7 @@ updateServices = ->
LDAP_DEFAULTS.bindSearch = undefined
, 2000

Settings.find().observe
RocketChat.models.Settings.find().observe
added: (record) ->
if /^LDAP_.+/.test record._id
updateServices()
Expand Down
5 changes: 3 additions & 2 deletions packages/rocketchat-ldap/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Package.describe({
});

Npm.depends({
ldapjs: "0.7.1",
ldapjs: "0.7.1",
});

// Loads all i18n.json files into tapi18nFiles
Expand All @@ -22,6 +22,7 @@ Package.onUse(function(api) {
api.versionsFrom('1.0.3.1');

// Commom
api.use('rocketchat:lib@0.0.1');
api.use('tap:i18n@1.5.1');
api.use('yasaricli:slugify');
api.use('coffeescript');
Expand All @@ -43,7 +44,7 @@ Package.onUse(function(api) {
api.addFiles('config_server.coffee', 'server');

api.addFiles(tapi18nFiles);

api.export('LDAP', 'server');
api.export('LDAP_DEFAULTS', 'server');
api.export('MeteorWrapperLdapjs');
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/lib/core.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# @namespace RocketChat
###

RocketChat = {}
RocketChat =
models: {}
32 changes: 23 additions & 9 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ Package.describe({

Package.onUse(function(api) {
api.versionsFrom('1.0');

api.use('reactive-var');
api.use('reactive-dict');
api.use('coffeescript');
api.use('random');
api.use('check');
api.use('underscore');
api.use('underscorestring:underscore.string');
api.use('monbro:mongodb-mapreduce-aggregation@1.0.1');

// TAPi18n
api.use('templating', 'client');
Expand All @@ -28,14 +30,33 @@ Package.onUse(function(api) {
api.imply('tap:i18n');
api.addFiles("package-tap.i18n", ["client", "server"]);


// COMMON
api.addFiles('lib/core.coffee');
api.addFiles('lib/callbacks.coffee');
api.addFiles('lib/slashCommand.coffee');

api.addFiles('settings/lib/settings.coffee');
// MODELS SERVER
api.addFiles('server/models/_Base.coffee', 'server');
api.addFiles('server/models/Users.coffee', 'server');
api.addFiles('server/models/Subscriptions.coffee', 'server');
api.addFiles('server/models/Rooms.coffee', 'server');
api.addFiles('server/models/Messages.coffee', 'server');
api.addFiles('server/models/Reports.coffee', 'server');

// Settings
api.addFiles('settings/lib/rocketchat.coffee');

api.addFiles('settings/server/models/Settings.coffee', 'server');
api.addFiles('settings/server/methods.coffee', 'server');
api.addFiles('settings/server/publication.coffee', 'server');
api.addFiles('settings/server/startup.coffee', 'server');
api.addFiles('settings/server/updateServices.coffee', 'server');
api.addFiles('settings/server/addOAuthService.coffee', 'server');

api.addFiles('settings/lib/settings.coffee');


// CLIENT
api.addFiles('client/Notifications.coffee', 'client');
api.addFiles('client/TabBar.coffee', 'client');
Expand All @@ -58,13 +79,6 @@ Package.onUse(function(api) {

api.addFiles('server/Notifications.coffee', 'server');

// Settings
api.addFiles('settings/server/methods.coffee', 'server');
api.addFiles('settings/server/publication.coffee', 'server');
api.addFiles('settings/server/startup.coffee', 'server');
api.addFiles('settings/server/updateServices.coffee', 'server');
api.addFiles('settings/server/addOAuthService.coffee', 'server');

api.addFiles('server/cdn.coffee', 'server');

// TAPi18n -- needs to be added last
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/server/Notifications.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RocketChat.Notifications = new class
roomId = eventName.split('/')[0]

user = Meteor.users.findOne @userId, {fields: {username: 1}}
return ChatRoom.findOne({_id: roomId, usernames: user.username}, {fields: {_id: 1}})?
return RocketChat.models.Rooms.findOneByIdContainigUsername(roomId, user.username, {fields: {_id: 1}})?

@streamUser.permissions.write -> return @userId?
@streamUser.permissions.read (eventName) ->
Expand Down
Loading