Livechat minor fixes and improvements

- Bypass user registration validations for livechat users - Closes
  #2276, #1963

- Set livechat count and order to zero when empty

- Pick a livechat departament if none select and there is more than one

- Fix livechat warning hide message

- Add autolinker to livechat
pull/3741/head
Diego Sampaio 10 years ago
parent 26ea288472
commit f3c1b255f3
  1. 1
      .eslintignore
  2. 10
      packages/rocketchat-livechat/app/client/lib/Autolinker.min.js
  3. 5
      packages/rocketchat-livechat/app/client/lib/autolinker.js
  4. 2
      packages/rocketchat-livechat/app/client/views/message.coffee
  5. 4
      packages/rocketchat-livechat/server/lib/Livechat.js
  6. 4
      packages/rocketchat-livechat/server/models/LivechatDepartment.js
  7. 11
      packages/rocketchat-ui-sidenav/side-nav/chatRoomItem.coffee
  8. 52
      server/lib/accounts.coffee

@ -24,3 +24,4 @@ packages/rocketchat-autolinker/lib/Autolinker.min.js
packages/rocketchat-livechat/lib/ua-parser.js
packages/rocketchat-videobridge/client/public/external_api.js
packages/rocketchat-lib/client/lib/localforage.min.js
packages/rocketchat-livechat/app/client/lib/Autolinker.min.js

File diff suppressed because one or more lines are too long

@ -0,0 +1,5 @@
/* globals livechatAutolinker, Autolinker */
var livechatAutolinker = new Autolinker({
twitter: false,
phone: false
});

@ -34,7 +34,7 @@ Template.message.helpers
# message = RocketChat.callbacks.run 'renderMessage', this
message = this
this.html = message.html.replace /\n/gm, '<br/>'
return this.html
return livechatAutolinker.link this.html
system: ->
return 'system' if this.t in ['s', 'p', 'f', 'r', 'au', 'ru', 'ul', 'wm', 'uj', 'livechat-close']

@ -31,10 +31,10 @@ RocketChat.Livechat = {
}
if (room == null) {
// if no department selected verify if there is only one active and use it
// if no department selected verify if there is at least one active and choose one randomly
if (!guest.department) {
var departments = RocketChat.models.LivechatDepartment.findEnabledWithAgents();
if (departments.count() === 1) {
if (departments.count() > 0) {
guest.department = departments.fetch()[0]._id;
}
}

@ -51,8 +51,8 @@ class LivechatDepartment extends RocketChat.models._Base {
agentId: agent.agentId,
departmentId: _id,
username: agent.username,
count: parseInt(agent.count),
order: parseInt(agent.order)
count: agent.count ? parseInt(agent.count) : 0,
order: agent.order ? parseInt(agent.order) : 0
});
});

@ -50,15 +50,14 @@ Template.chatRoomItem.events
rid = this.rid
name = this.name
warnText = switch
when this.t == 'c' then 'Hide_Room_Warning'
when this.t == 'p' then 'Hide_Group_Warning'
when this.t == 'd' then 'Hide_Private_Warning'
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: t(warnText, name)
text: if warnText then t(warnText, name) else ''
type: 'warning'
showCancelButton: true
confirmButtonColor: '#DD6B55'

@ -2,21 +2,6 @@
accountsConfig = { forbidClientAccountCreation: true, loginExpirationInDays: RocketChat.settings.get 'Accounts_LoginExpiration' }
Accounts.config accountsConfig
RocketChat.settings.get 'Accounts_AllowedDomainsList', (_id, value) ->
domainWhiteList = _.map value.split(','), (domain) -> domain.trim()
restrictCreationByEmailDomain = if domainWhiteList.length == 1 then domainWhiteList[0] else (email) ->
ret = false
for domain in domainWhiteList
if email.match('@' + RegExp.escape(domain) + '$')
ret = true
break;
return ret
delete Accounts._options['restrictCreationByEmailDomain']
if not _.isEmpty value
Accounts.config({ restrictCreationByEmailDomain: restrictCreationByEmailDomain });
Accounts.emailTemplates.siteName = RocketChat.settings.get 'Site_Name';
Accounts.emailTemplates.from = "#{RocketChat.settings.get 'Site_Name'} <#{RocketChat.settings.get 'From_Email'}>";
@ -106,7 +91,9 @@ Accounts.insertUserDoc = _.wrap Accounts.insertUserDoc, (insertUserDoc, options,
RocketChat.authz.addUserRoles(_id, roles)
RocketChat.callbacks.run 'afterCreateUser', options, user
Meteor.defer ->
RocketChat.callbacks.run 'afterCreateUser', options, user
return _id
Accounts.validateLoginAttempt (login) ->
@ -115,6 +102,10 @@ Accounts.validateLoginAttempt (login) ->
if login.allowed isnt true
return login.allowed
# bypass for livechat users
if login.user.type is 'visitor'
return true
if !!login.user?.active isnt true
throw new Meteor.Error 'error-user-is-not-activated', 'User is not activated', { function: 'Accounts.validateLoginAttempt' }
return false
@ -136,6 +127,35 @@ Accounts.validateLoginAttempt (login) ->
return true
Accounts.validateNewUser (user) ->
# bypass for livechat users
if user.type is 'visitor'
return true
if RocketChat.settings.get('Accounts_Registration_AuthenticationServices_Enabled') is false and RocketChat.settings.get('LDAP_Enable') is false and not user.services?.password?
throw new Meteor.Error 'registration-disabled-authentication-services', 'User registration is disabled for authentication services'
return true
Accounts.validateNewUser (user) ->
# bypass for livechat users
if user.type is 'visitor'
return true
domainWhiteList = RocketChat.settings.get('Accounts_AllowedDomainsList')
if _.isEmpty s.trim(domainWhiteList)
return true
domainWhiteList = _.map(domainWhiteList.split(','), (domain) -> domain.trim())
if user.emails?.length > 0
ret = false
email = user.emails[0].address
for domain in domainWhiteList
if email.match('@' + RegExp.escape(domain) + '$')
ret = true
break
return ret
return true

Loading…
Cancel
Save