diff --git a/client/views/app/sideNav/createChannelFlex.coffee b/client/views/app/sideNav/createChannelFlex.coffee index 7e0681268af2..710eccb74fd6 100644 --- a/client/views/app/sideNav/createChannelFlex.coffee +++ b/client/views/app/sideNav/createChannelFlex.coffee @@ -84,6 +84,9 @@ Template.createChannelFlex.events if err.error is 'name-invalid' instance.error.set({ invalid: true }) return + if err.error is 'duplicate-name' + instance.error.set({ duplicate: true }) + return else return toastr.error err.reason diff --git a/client/views/app/sideNav/createChannelFlex.html b/client/views/app/sideNav/createChannelFlex.html index 8c94d75375a8..2f5e30431261 100644 --- a/client/views/app/sideNav/createChannelFlex.html +++ b/client/views/app/sideNav/createChannelFlex.html @@ -34,6 +34,12 @@

{{_ "Create_new_public_channel" }}

{{{_ "Invalid_room_name" roomName}}} {{/if}} + {{#if error.duplicate}} +
+ {{_ "Oops!"}} + {{{_ "Duplicate_channel_name" roomName}}} +
+ {{/if}}
diff --git a/client/views/app/sideNav/privateGroupsFlex.coffee b/client/views/app/sideNav/privateGroupsFlex.coffee index 4ad0f0a5c49f..9ba8fa3d34a5 100644 --- a/client/views/app/sideNav/privateGroupsFlex.coffee +++ b/client/views/app/sideNav/privateGroupsFlex.coffee @@ -5,6 +5,9 @@ Template.privateGroupsFlex.helpers name: -> return Template.instance().selectedUserNames[this.valueOf()] + groupName: -> + return Template.instance().groupName.get() + error: -> return Template.instance().error.get() @@ -68,24 +71,35 @@ Template.privateGroupsFlex.events 'click .save-pvt-group': (e, instance) -> err = SideNav.validate() + instance.groupName.set instance.find('#pvt-group-name').value + console.log err if not err Meteor.call 'createPrivateGroup', instance.find('#pvt-group-name').value, instance.selectedUsers.get(), (err, result) -> if err + console.log err + if err.error is 'name-invalid' + instance.error.set({ invalid: true }) + return + if err.error is 'duplicate-name' + instance.error.set({ duplicate: true }) + return return toastr.error err.reason SideNav.closeFlex() instance.clearForm() FlowRouter.go 'room', { _id: result.rid } else - Template.instance().error.set(err) + Template.instance().error.set({fields: err}) Template.privateGroupsFlex.onCreated -> instance = this instance.selectedUsers = new ReactiveVar [] instance.selectedUserNames = {} instance.error = new ReactiveVar [] + instance.groupName = new ReactiveVar '' instance.clearForm = -> instance.error.set([]) + instance.groupName.set('') instance.selectedUsers.set([]) instance.find('#pvt-group-name').value = '' instance.find('#pvt-group-members').value = '' diff --git a/client/views/app/sideNav/privateGroupsFlex.html b/client/views/app/sideNav/privateGroupsFlex.html index 4e6d3faa2f02..24e9050283e2 100644 --- a/client/views/app/sideNav/privateGroupsFlex.html +++ b/client/views/app/sideNav/privateGroupsFlex.html @@ -20,14 +20,26 @@

{{_ "Create_new_private_group"}}

{{/each}}
- {{#if error}} + {{#if error.fields}}
- Ops! - {{#each error}} -

{{_ "The_field_is_required" error}}

+ {{_ "Oops!"}} + {{#each error.fields}} +

{{_ "The_field_is_required" .}}

{{/each}}
{{/if}} + {{#if error.invalid}} +
+ {{_ "Oops!"}} + {{{_ "Invalid_room_name" groupName}}} +
+ {{/if}} + {{#if error.duplicate}} +
+ {{_ "Oops!"}} + {{{_ "Duplicate_private_group_name" groupName}}} +
+ {{/if}}
diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 5568cafba6d1..d5e9c678042e 100755 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -40,6 +40,8 @@ "Created_at" : "Created at", "Direct_Messages" : "Direct Messages", "Deleted" : "Deleted!", + "Duplicate_private_group_name" : "A Private Group with the name, '%s', exists", + "Duplicate_channel_name" : "A Channel with the name, '%s', exists", "edited" : "edited", "Email_or_username" : "Email or username", "Email_verified" : "Email verified", diff --git a/server/methods/createChannel.coffee b/server/methods/createChannel.coffee index e3838f42470f..8b80d937b9e1 100644 --- a/server/methods/createChannel.coffee +++ b/server/methods/createChannel.coffee @@ -15,7 +15,7 @@ Meteor.methods # avoid duplicate names if ChatRoom.findOne({name:name}) - throw new Meteor.Error 'duplicate-name', "A Channel with the same name exists" + throw new Meteor.Error 'duplicate-name' # name = s.slugify name diff --git a/server/methods/createPrivateGroup.coffee b/server/methods/createPrivateGroup.coffee index ef8d8ba4315a..40d252a649d2 100644 --- a/server/methods/createPrivateGroup.coffee +++ b/server/methods/createPrivateGroup.coffee @@ -5,6 +5,9 @@ Meteor.methods console.log '[methods] createPrivateGroup -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments + if not /^[0-9a-z-_]+$/i.test name + throw new Meteor.Error 'name-invalid' + now = new Date() me = Meteor.user() @@ -15,7 +18,7 @@ Meteor.methods # avoid duplicate names if ChatRoom.findOne({name:name}) - throw new Meteor.Error 'duplicate-name', "A private group with the same name exists" + throw new Meteor.Error 'duplicate-name' # create new room rid = ChatRoom.insert