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

added default field

parent f38bdecd
No related merge requests found
Showing
with 129 additions and 81 deletions
Template.channelSettingsMailMessages.helpers
canSendEmail: ->
return FlowRouter.getRouteName() isnt 'admin-rooms'
Template.channelSettingsMailMessages.events
'click button.mail-messages': (e, t) ->
Session.set 'channelSettingsMailMessages', Session.get('openedRoom')
......
<template name="channelSettingsMailMessages">
<li>
<label>{{_ "Mail_Messages"}}</label>
<div>
<button type="button" class="button primary mail-messages">{{_ "Choose_messages"}}</button>
</div>
</li>
{{#if canSendEmail}}
<li>
<label>{{_ "Mail_Messages"}}</label>
<div>
<button type="button" class="button primary mail-messages">{{_ "Choose_messages"}}</button>
</div>
</li>
{{/if}}
</template>
......@@ -10,19 +10,19 @@ Template.channelSettings.helpers
channelSettings: ->
return RocketChat.ChannelSettings.getOptions()
roomTypeDescription: ->
roomType = ChatRoom.findOne(@rid)?.t
roomType = ChatRoom.findOne(@rid, { fields: { t: 1 }})?.t
if roomType is 'c'
return t('Channel')
else if roomType is 'p'
return t('Private_Group')
roomName: ->
return ChatRoom.findOne(@rid)?.name
return ChatRoom.findOne(@rid, { fields: { name: 1 }})?.name
roomTopic: ->
return ChatRoom.findOne(@rid)?.topic
return ChatRoom.findOne(@rid, { fields: { topic: 1 }})?.topic
archivationState: ->
return ChatRoom.findOne(@rid)?.archived
return ChatRoom.findOne(@rid, { fields: { archived: 1 }})?.archived
archivationStateDescription: ->
archivationState = ChatRoom.findOne(@rid)?.archived
archivationState = ChatRoom.findOne(@rid, { fields: { archived: 1 }})?.archived
if archivationState is true
return t('Room_archivation_state_true')
else
......
......@@ -3,12 +3,15 @@ Meteor.methods
unless Match.test rid, String
throw new Meteor.Error 'invalid-rid', 'Invalid room'
if setting not in ['roomName', 'roomTopic', 'roomType']
if setting not in ['roomName', 'roomTopic', 'roomType', 'default']
throw new Meteor.Error 'invalid-settings', 'Invalid settings provided'
unless RocketChat.authz.hasPermission(Meteor.userId(), 'edit-room', rid)
throw new Meteor.Error 503, 'Not authorized'
if setting is 'default' and not RocketChat.authz.hasPermission(@userId, 'view-room-administration')
throw new Meteor.Error 503, 'Not authorized'
room = RocketChat.models.Rooms.findOneById rid
if room?
switch setting
......@@ -27,5 +30,7 @@ Meteor.methods
else
message = TAPi18n.__('Private_Group')
RocketChat.models.Messages.createRoomSettingsChangedWithTypeRoomIdMessageAndUser 'room_changed_privacy', rid, message, Meteor.user()
when 'default'
RocketChat.models.Rooms.saveDefaultById rid, value
return true
......@@ -47,6 +47,9 @@ RocketChat.models.Rooms = new class extends RocketChat.models._Base
# FIND
findById: (roomId) ->
return @find { _id: roomId }, options
findByType: (type, options) ->
query =
t: type
......@@ -361,6 +364,15 @@ RocketChat.models.Rooms = new class extends RocketChat.models._Base
return @update query, update
saveDefaultById: (_id, defaultValue) ->
query =
_id: _id
update =
$set:
default: defaultValue is 'true'
return @update query, update
# INSERT
createWithTypeNameUserAndUsernames: (type, name, user, usernames, extraData) ->
......
Template.adminRoomInfo.helpers
canDeleteRoom: ->
return RocketChat.authz.hasAtLeastOnePermission("delete-#{@t}")
type: ->
return if @t is 'd' then 'at' else if @t is 'p' then 'lock' else 'hash'
name: ->
if @t is 'c' or @t is 'p'
return @name
else if @t is 'd'
return @usernames.join ' x '
route: ->
return switch this.t
when 'd'
FlowRouter.path('direct', {username: @name})
when 'p'
FlowRouter.path('group', {name: @name})
when 'c'
FlowRouter.path('channel', {name: @name})
Template.adminRoomInfo.events
'click .delete': ->
_id = Template.currentData()._id
swal {
title: t('Are_you_sure')
text: t('Delete_Room_Warning')
type: 'warning'
showCancelButton: true
confirmButtonColor: '#DD6B55'
confirmButtonText: t('Yes_delete_it')
cancelButtonText: t('Cancel')
closeOnConfirm: false
html: false
}, ->
swal
title: t('Deleted')
text: t('Room_has_been_deleted')
type: 'success'
timer: 2000
showConfirmButton: false
Meteor.call 'eraseRoom', _id, (error, result) ->
if error
toastr.error error.reason
<template name="adminRoomInfo">
{{#unless hasPermission 'view-room-administration'}}
<p>{{_ "You_are_not_authorized_to_view_this_page"}}</p>
{{else}}
<div>
<h3><a href="{{route}}"><i class="icon-{{type}}"></i> {{name}}</a></h3>
</div>
<nav>
{{#if canDeleteRoom}}
<button class='button delete red'><span><i class='icon-trash'></i> {{_ "Delete"}}</span></button>
{{/if}}
<button class='button delete'><span>{{_ "Make_default"}}</span></button>
</nav>
{{/unless}}
</template>
......@@ -45,10 +45,18 @@ Template.adminRooms.onCreated ->
id: 'admin-room',
i18nTitle: 'Room_Info',
icon: 'octicon octicon-info',
template: 'adminRoomInfo',
template: 'channelSettings',
order: 1
});
RocketChat.ChannelSettings.addOption
id: 'make-default'
template: 'channelSettingsDefault'
data: ->
return Session.get('adminRoomsSelected')
validation: ->
return RocketChat.authz.hasAllPermission('view-room-administration')
@autorun ->
filter = instance.filter.get()
types = instance.types.get()
......@@ -73,7 +81,7 @@ Template.adminRooms.onCreated ->
if types.length
query['t'] = { $in: types }
return ChatRoom.find(query, { limit: instance.limit?.get(), sort: { name: 1 } })
return ChatRoom.find(query, { limit: instance.limit?.get(), sort: { default: -1, name: 1 } })
@getSearchTypes = ->
return _.map $('[name=room-type]:checked'), (input) -> return $(input).val()
......@@ -96,10 +104,11 @@ Template.adminRooms.events
'click .room-info': (e) ->
e.preventDefault()
# Session.set 'adminRoomsSelected', @_id
RocketChat.TabBar.setData @
RocketChat.TabBar.setTemplate('adminRoomInfo')
# RocketChat.TabBar.openFlex()
Session.set('adminRoomsSelected', { rid: @_id });
RocketChat.TabBar.setData { rid: @_id }
RocketChat.TabBar.setTemplate('channelSettings')
'click .load-more': (e, t) ->
e.preventDefault()
......
<template name="channelSettingsDefault">
{{#if canMakeDefault}}
<li>
<label>{{_ "Default"}}</label>
<div>
{{#if editing 'default'}}
<label><input type="radio" name="default" class="editing" value="true" checked="{{$eq roomDefault true}}" /> {{_ "True"}}</label>
<label><input type="radio" name="default" value="false" checked="{{$neq roomDefault true}}" /> {{_ "False"}}</label>
<button type="button" class="button secondary cancel">{{_ "Cancel"}}</button>
<button type="button" class="button primary save">{{_ "Save"}}</button>
{{else}}
<span>{{defaultDescription}} <i class="octicon octicon-pencil" data-edit="default"></i></span>
{{/if}}
</div>
</li>
{{/if}}
</template>
Template.channelSettingsDefault.helpers({
canMakeDefault() {
var room = ChatRoom.findOne(this.rid, { fields: { t: 1 }});
return room && room.t === 'c';
},
editing(field) {
return Template.instance().editing.get() === field;
},
roomDefault() {
var room = ChatRoom.findOne(this.rid, { fields: { default: 1 }});
if (room) {
return room.default;
}
},
defaultDescription() {
var room = ChatRoom.findOne(this.rid, { fields: { default: 1 }});
if (room && room.default) {
return t('True');
} else {
return t('False');
}
}
});
Template.channelSettingsDefault.events({
'click [data-edit]'(e, t) {
e.preventDefault();
t.editing.set($(e.currentTarget).data('edit'));
setTimeout(() => {
t.$('input.editing').focus().select();
}, 100);
},
'click .cancel'(e, t) {
e.preventDefault();
t.editing.set();
},
'click .save'(e, t) {
e.preventDefault();
Meteor.call('saveRoomSettings', this.rid, 'default', $('input[name=default]:checked').val(), (err, result) => {
if (err) {
if (err.error === 'invalid-room-type') {
return toastr.error(TAPi18n.__(err.reason, err.details.roomType));
}
return toastr.error(TAPi18n.__(err.reason));
}
toastr.success(TAPi18n.__('Room_type_changed_successfully'));
});
t.editing.set();
}
});
Template.channelSettingsDefault.onCreated(function() {
this.editing = new ReactiveVar();
});
......@@ -26,8 +26,9 @@ Package.onUse(function(api) {
api.addFiles('admin/adminFlex.html', 'client');
api.addFiles('admin/adminInfo.html', 'client');
api.addFiles('admin/rooms/adminRoomInfo.html', 'client');
api.addFiles('admin/rooms/adminRooms.html', 'client');
api.addFiles('admin/rooms/channelSettingsDefault.html', 'client');
api.addFiles('admin/rooms/channelSettingsDefault.js', 'client');
api.addFiles('admin/users/adminInviteUser.html', 'client');
api.addFiles('admin/users/adminUserChannels.html', 'client');
......@@ -40,7 +41,6 @@ Package.onUse(function(api) {
api.addFiles('admin/adminFlex.coffee', 'client');
api.addFiles('admin/adminInfo.coffee', 'client');
api.addFiles('admin/rooms/adminRoomInfo.coffee', 'client');
api.addFiles('admin/rooms/adminRooms.coffee', 'client');
api.addFiles('admin/users/adminInviteUser.coffee', 'client');
......
......@@ -17,10 +17,12 @@ Meteor.publish('adminRooms', function(filter, types, limit) {
u: 1,
usernames: 1,
muted: 1,
default: 1
default: 1,
topic: 1
},
limit: limit,
sort: {
default: -1,
name: 1
}
};
......
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