Skip to content
Snippets Groups Projects
Commit 18fd157f authored by Alex Brazier's avatar Alex Brazier
Browse files

PR changes/fixes

parent 1d7c70e8
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@
- [FIX] Incoming integrations would break when trying to use the `Store` feature.
- [FIX] Outgoing webhooks which have an error and they're retrying would still retry even if the integration was disabled. (#4835)
- [FIX] Removed Deprecated Package rocketchat:sharedsecret.
- [BREAK] `getUsersOfRoom` API to return array of objects with user and username, instead of array of strings
## 0.54.2 - 2017-Mar-24
......
......@@ -95,7 +95,7 @@ const CROWD = class CROWD {
};
if (crowdUser.displayname) {
RocketChat._setRealName(user._id, crowdUser.displayname);
RocketChat._setRealName(id, crowdUser.displayname);
}
Meteor.users.update(id, {
......
......@@ -87,7 +87,7 @@ Package.onUse(function(api) {
api.addFiles('server/functions/settings.coffee', 'server');
api.addFiles('server/functions/setUserAvatar.js', 'server');
api.addFiles('server/functions/setUsername.coffee', 'server');
api.addFiles('server/functions/setRealName.coffee', 'server');
api.addFiles('server/functions/setRealName.js', 'server');
api.addFiles('server/functions/setEmail.js', 'server');
api.addFiles('server/functions/unarchiveRoom.js', 'server');
api.addFiles('server/functions/updateMessage.js', 'server');
......
RocketChat._setRealName = (userId, name) ->
name = s.trim name
if not userId or not name
return false
user = RocketChat.models.Users.findOneById userId
# User already has desired name, return
if user.name is name
return user
previousName = user.name
if previousName
RocketChat.models.Messages.updateAllNamesByUserId user._id, name
RocketChat.models.Subscriptions.setRealNameForDirectRoomsWithUsername user.username, name
# Set new name
RocketChat.models.Users.setName user._id, name
user.name = name
return user
RocketChat.setRealName = RocketChat.RateLimiter.limitFunction RocketChat._setRealName, 1, 60000,
0: () -> return not Meteor.userId() or not RocketChat.authz.hasPermission(Meteor.userId(), 'edit-other-user-info') # Administrators have permission to change others names, so don't limit those
RocketChat._setRealName = function(userId, name) {
name = s.trim(name);
if (!userId || !name) {
return false;
}
const user = RocketChat.models.Users.findOneById(userId);
// User already has desired name, return
if (user.name === name) {
return user;
}
const previousName = user.name;
if (previousName) {
RocketChat.models.Messages.updateAllNamesByUserId(user._id, name);
RocketChat.models.Subscriptions.setRealNameForDirectRoomsWithUsername(user.username, name);
}
// Set new name
RocketChat.models.Users.setName(user._id, name);
user.name = name;
return user;
};
RocketChat.setRealName = RocketChat.RateLimiter.limitFunction(RocketChat._setRealName, 1, 60000, {
0() { return !Meteor.userId() || !RocketChat.authz.hasPermission(Meteor.userId(), 'edit-other-user-info'); } // Administrators have permission to change others names, so don't limit those
});
Template.membersList.helpers
tAddUsers: ->
return t('Add_users')
isGroupChat: ->
return ChatRoom.findOne(this.rid, { reactive: false })?.t in ['c', 'p']
isDirectChat: ->
return ChatRoom.findOne(this.rid, { reactive: false })?.t is 'd'
seeAll: ->
if Template.instance().showAllUsers.get()
return t('Show_only_online')
else
return t('Show_all')
roomUsers: ->
onlineUsers = RoomManager.onlineUsers.get()
roomUsers = Template.instance().users.get()
room = ChatRoom.findOne(this.rid)
roomMuted = room?.muted or []
userUtcOffset = Meteor.user().utcOffset
totalOnline = 0
users = roomUsers.map (user) ->
if onlineUsers[user.username]?
totalOnline++
utcOffset = onlineUsers[user.username].utcOffset
if utcOffset?
if utcOffset is userUtcOffset
utcOffset = ""
else if utcOffset > 0
utcOffset = "+#{utcOffset}"
else
utcOffset = "(UTC #{utcOffset})"
return {
user: user
status: onlineUsers[user.username]?.status
muted: user.username in roomMuted
utcOffset: utcOffset
}
users = _.sortBy users, (u) -> u.user.username
# show online users first.
# sortBy is stable, so we can do this
users = _.sortBy users, (u) -> !u.status?
usersLimit = Template.instance().usersLimit.get()
hasMore = users.length > usersLimit
users = _.first(users, usersLimit)
totalShowing = users.length
ret =
_id: this.rid
total: Template.instance().total.get()
totalShowing: totalShowing
loading: Template.instance().loading.get()
totalOnline: totalOnline
users: users
hasMore: hasMore
return ret
canAddUser: ->
roomData = Session.get('roomData' + this._id)
return '' unless roomData
return switch roomData.t
when 'p' then RocketChat.authz.hasAtLeastOnePermission ['add-user-to-any-p-room', 'add-user-to-joined-room'], this._id
when 'c' then RocketChat.authz.hasAtLeastOnePermission ['add-user-to-any-c-room', 'add-user-to-joined-room'], this._id
else false
autocompleteSettingsAddUser: ->
return {
limit: 10
# inputDelay: 300
rules: [
{
collection: 'UserAndRoom'
subscription: 'userAutocomplete'
field: 'username'
template: Template.userSearch
noMatchTemplate: Template.userSearchEmpty
matchAll: true
filter:
exceptions: [Meteor.user().username]
selector: (match) ->
return { term: match }
sort: 'username'
}
]
}
showUserInfo: ->
webrtc = WebRTC.getInstanceByRoomId(this.rid)
videoActive = webrtc?.localUrl?.get()? or webrtc?.remoteItems?.get()?.length > 0
return Template.instance().showDetail.get() and not videoActive
userInfoDetail: ->
room = ChatRoom.findOne(this.rid, { fields: { t: 1 } })
return {
tabBar: Template.currentData().tabBar
username: Template.instance().userDetail.get()
clear: Template.instance().clearUserDetail
showAll: room?.t in ['c', 'p']
hideAdminControls: room?.t in ['c', 'p', 'd']
video: room?.t in ['d']
}
displayName: ->
return if RocketChat.settings.get('UI_Use_Real_Name') then this.user.name else this.user.username
Template.membersList.events
'click .see-all': (e, instance) ->
seeAll = instance.showAllUsers.get()
instance.showAllUsers.set(!seeAll)
if not seeAll
instance.usersLimit.set 100
'autocompleteselect #user-add-search': (event, template, doc) ->
roomData = Session.get('roomData' + template.data.rid)
if roomData.t in ['c', 'p']
Meteor.call 'addUserToRoom', { rid: roomData._id, username: doc.username }, (error, result) ->
if error
return handleError(error)
$('#user-add-search').val('')
'click .show-more-users': (e, instance) ->
instance.usersLimit.set(instance.usersLimit.get() + 100)
Template.membersList.onCreated ->
@showAllUsers = new ReactiveVar false
@usersLimit = new ReactiveVar 100
@userDetail = new ReactiveVar
@showDetail = new ReactiveVar false
@users = new ReactiveVar []
@total = new ReactiveVar
@loading = new ReactiveVar true
@tabBar = Template.instance().tabBar
Tracker.autorun =>
return unless this.data.rid?
@loading.set true
Meteor.call 'getUsersOfRoom', this.data.rid, this.showAllUsers.get(), (error, users) =>
@users.set users.records
@total.set users.total
@loading.set false
@clearUserDetail = =>
@showDetail.set(false)
setTimeout =>
@clearRoomUserDetail()
, 500
@showUserDetail = (username) =>
@showDetail.set(username?)
@userDetail.set(username)
@clearRoomUserDetail = @data.clearUserDetail
@autorun =>
data = Template.currentData()
@showUserDetail data.userDetail
......@@ -138,7 +138,7 @@ Template.membersList.helpers({
};
},
displayName() {
if (RocketChat.settings.get('UI_Use_Real_Name')) {
if (RocketChat.settings.get('UI_Use_Real_Name') && this.user.name) {
return this.user.name;
}
......
Template.accountBox.helpers
myUserInfo: ->
visualStatus = "online"
username = Meteor.user()?.username
name = Meteor.user()?.name
switch Session.get('user_' + username + '_status')
when "away"
visualStatus = t("away")
when "busy"
visualStatus = t("busy")
when "offline"
visualStatus = t("invisible")
return {
name: Session.get('user_' + username + '_name')
status: Session.get('user_' + username + '_status')
visualStatus: visualStatus
_id: Meteor.userId()
username: username
fname: name
}
showAdminOption: ->
return RocketChat.authz.hasAtLeastOnePermission( ['view-statistics', 'view-room-administration', 'view-user-administration', 'view-privileged-setting' ]) or RocketChat.AdminBox.getOptions().length > 0
registeredMenus: ->
return AccountBox.getItems()
Template.accountBox.events
'click .options .status': (event) ->
event.preventDefault()
AccountBox.setStatus(event.currentTarget.dataset.status)
RocketChat.callbacks.run('userStatusManuallySet', event.currentTarget.dataset.status)
'click .account-box': (event) ->
AccountBox.toggle()
'click #logout': (event) ->
event.preventDefault()
user = Meteor.user()
Meteor.logout ->
RocketChat.callbacks.run 'afterLogoutCleanUp', user
Meteor.call('logoutCleanUp', user)
FlowRouter.go 'home'
'click #avatar': (event) ->
FlowRouter.go 'changeAvatar'
'click #account': (event) ->
SideNav.setFlex "accountFlex"
SideNav.openFlex()
FlowRouter.go 'account'
'click #admin': ->
SideNav.setFlex "adminFlex"
SideNav.openFlex()
FlowRouter.go 'admin-info'
'click .account-link': (event) ->
event.stopPropagation();
event.preventDefault();
AccountBox.openFlex()
'click .account-box-item': ->
if @href
FlowRouter.go @href
if @sideNav?
SideNav.setFlex @sideNav
SideNav.openFlex()
Template.accountBox.onRendered ->
AccountBox.init()
Template.chatRoomItem.helpers
alert: ->
if FlowRouter.getParam('_id') isnt this.rid or not document.hasFocus()
return this.alert
unread: ->
if (FlowRouter.getParam('_id') isnt this.rid or not document.hasFocus()) and this.unread > 0
return this.unread
userStatus: ->
userStatus = RocketChat.roomTypes.getUserStatus(this.t, this.rid);
return 'status-' + (userStatus or 'offline')
name: ->
if RocketChat.settings.get('UI_Use_Real_Name') and this.fname
return this.fname
else
return this.name
roomIcon: ->
return RocketChat.roomTypes.getIcon this.t
active: ->
if Session.get('openedRoom') is this.rid
return 'active'
canLeave: ->
roomData = Session.get('roomData' + this.rid)
return false unless roomData
if (roomData.cl? and not roomData.cl) or roomData.t is 'd'
return false
else
return true
route: ->
return RocketChat.roomTypes.getRouteLink @t, @
archived: ->
return if this.archived then 'archived'
Template.chatRoomItem.rendered = ->
if not (FlowRouter.getParam('_id')? and FlowRouter.getParam('_id') is this.data.rid) and not this.data.ls and this.data.alert is true
KonchatNotification.newRoom(this.data.rid)
Template.chatRoomItem.events
'click .open-room': (e) ->
menu.close()
'click .hide-room': (e) ->
e.stopPropagation()
e.preventDefault()
rid = this.rid
name = this.name
warnText = switch this.t
when 'c' then 'Hide_Room_Warning'
when 'p' then 'Hide_Group_Warning'
when 'd' then 'Hide_Private_Warning'
swal {
title: t('Are_you_sure')
text: if warnText then t(warnText, name) else ''
type: 'warning'
showCancelButton: true
confirmButtonColor: '#DD6B55'
confirmButtonText: t('Yes_hide_it')
cancelButtonText: t('Cancel')
closeOnConfirm: true
html: false
}, ->
if FlowRouter.getRouteName() in ['channel', 'group', 'direct'] and Session.get('openedRoom') is rid
FlowRouter.go 'home'
Meteor.call 'hideRoom', rid, (err) ->
if err
handleError(err)
else
if rid is Session.get('openedRoom')
Session.delete('openedRoom')
'click .leave-room': (e) ->
e.stopPropagation()
e.preventDefault()
rid = this.rid
name = this.name
warnText = switch
when this.t == 'c' then 'Leave_Room_Warning'
when this.t == 'p' then 'Leave_Group_Warning'
when this.t == 'd' then 'Leave_Private_Warning'
swal {
title: t('Are_you_sure')
text: t(warnText, name)
type: 'warning'
showCancelButton: true
confirmButtonColor: '#DD6B55'
confirmButtonText: t('Yes_leave_it')
cancelButtonText: t('Cancel')
closeOnConfirm: false
html: false
}, (isConfirm) ->
if isConfirm
Meteor.call 'leaveRoom', rid, (err) ->
if err
swal {
title: t('Warning')
text: handleError(err, false)
type: 'warning'
html: false
}
else
swal.close()
if FlowRouter.getRouteName() in ['channel', 'group', 'direct'] and Session.get('openedRoom') is rid
FlowRouter.go 'home'
RoomManager.close rid
else
swal.close()
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