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

[NEW] Improve room types API and usages #9009

Merged
merged 27 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
882a8d2
enable channel settings for custom room types
mrsimpson Sep 23, 2017
cf6ea72
enable members list for custom room types
mrsimpson Sep 23, 2017
0c53dd3
satisfy es-lint
mrsimpson Sep 25, 2017
0e4f824
added option to specify creation template for custom room types
mrsimpson Sep 27, 2017
929e846
custom room types: prevent renaming
mrsimpson Sep 28, 2017
3321156
custom room types: include in global search
mrsimpson Sep 28, 2017
9d2381e
Custom room type: handle not-provided creation template
mrsimpson Sep 29, 2017
c62f9e8
Enable custom room type creation templates
mrsimpson Sep 30, 2017
65c4eec
Provide wrapper for room creation for better extensibility
mrsimpson Oct 1, 2017
5b6b5f8
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
mrsimpson Oct 1, 2017
06226f2
Replace hard-coded room types with "interface"-method-calls
mrsimpson Oct 1, 2017
b2a425f
thx, codacy
mrsimpson Oct 2, 2017
37c3672
Room definitions are more typed but extended classes have full contro…
graywolf336 Oct 12, 2017
d4059ae
Move the settings configuration over to an ENUM based.
graywolf336 Oct 12, 2017
17e7549
Fix the tests failing due to some items not being on all settings
graywolf336 Oct 12, 2017
a7c04e1
[DOC] Update the rocketchat:lib readme with information about providi…
graywolf336 Oct 14, 2017
685593a
Fix the room name's not being displayed in the admin rooms
graywolf336 Oct 16, 2017
fa20b86
Add creation validation configuration, e. g. in order to check whethe…
mrsimpson Oct 17, 2017
b2b09a3
Adapt warning-text for leaving a room. Fixes #92
mrsimpson Oct 23, 2017
03e23cf
Move profile in membersList to interface method
mrsimpson Oct 26, 2017
5f3cce9
merge develop for smaller diff
mrsimpson Oct 27, 2017
a480c20
Add interface method for UI-texts.
mrsimpson Oct 28, 2017
c5c0ece
Added a closing text constant
mrsimpson Oct 28, 2017
916afa5
Allow room types to provide an own "no subscriptions yet" text
mrsimpson Nov 3, 2017
a38bf42
Merge assistify:core/#8264-room-types and fix the conflicts.
graywolf336 Dec 4, 2017
7a098ad
Merge develop and fix the conflicts
graywolf336 Dec 4, 2017
5f068ca
Fix the tokenpass room type not aligning
graywolf336 Dec 4, 2017
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import toastr from 'toastr';
import s from 'underscore.string';

import { RocketChat, RoomSettingsEnum } from 'meteor/rocketchat:lib';

Template.channelSettings.helpers({
toArray(obj) {
return Object.keys(obj).map((key) => {
Expand All @@ -22,12 +24,6 @@ Template.channelSettings.helpers({
}
return obj && obj[key];
},
showSetting(setting, room) {
if (setting.showInDirect === false) {
return room.t !== 'd';
}
return true;
},
settings() {
return Template.instance().settings;
},
Expand All @@ -53,15 +49,17 @@ Template.channelSettings.helpers({
t: 1
}
});

const roomType = room && room.t;
return roomType && RocketChat.authz.hasAtLeastOnePermission(`delete-${ roomType }`, this.rid);
return roomType && RocketChat.roomTypes.roomTypes[room.t].canBeDeleted(room);
},
readOnly() {
const room = ChatRoom.findOne(this.rid, {
fields: {
ro: 1
}
});

return room && room.ro;
},
has(v, key) {
Expand All @@ -73,6 +71,7 @@ Template.channelSettings.helpers({
ro: 1
}
});

return t(room && room.ro ? 'True' : 'False');
},
showingValue(field) {
Expand Down Expand Up @@ -164,7 +163,7 @@ Template.channelSettings.onCreated(function() {
type: 'text',
label: 'Name',
canView(room) {
return room.t !== 'd';
return RocketChat.roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.NAME);
},
canEdit(room) {
return RocketChat.authz.hasAllPermission('edit-room', room._id);
Expand All @@ -173,19 +172,18 @@ Template.channelSettings.onCreated(function() {
if (RocketChat.settings.get('UI_Allow_room_names_with_special_chars')) {
return room.fname || room.name;
}

return room.name;
},
save(value, room) {
let nameValidation;
if (!RocketChat.authz.hasAllPermission('edit-room', room._id) || (room.t !== 'c' && room.t !== 'p')) {
return toastr.error(t('error-not-allowed'));
}
if (!RocketChat.settings.get('UI_Allow_room_names_with_special_chars')) {
try {
nameValidation = new RegExp(`^${ RocketChat.settings.get('UTF8_Names_Validation') }$`);
} catch (error1) {
nameValidation = new RegExp('^[0-9a-zA-Z-_.]+$');
}

if (!nameValidation.test(value)) {
return toastr.error(t('error-invalid-room-name', {
room_name: {
Expand All @@ -194,32 +192,36 @@ Template.channelSettings.onCreated(function() {
}));
}
}
Meteor.call('saveRoomSettings', room._id, 'roomName', value, function(err) {

Meteor.call('saveRoomSettings', room._id, RoomSettingsEnum.NAME, value, function(err) {
if (err) {
return handleError(err);
}

RocketChat.callbacks.run('roomNameChanged', {
_id: room._id,
name: value
});

return toastr.success(TAPi18n.__('Room_name_changed_successfully'));
});
}
},
topic: {
type: 'markdown',
label: 'Topic',
canView() {
return true;
canView(room) {
return RocketChat.roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.TOPIC);
},
canEdit(room) {
return RocketChat.authz.hasAllPermission('edit-room', room._id);
},
save(value, room) {
return Meteor.call('saveRoomSettings', room._id, 'roomTopic', value, function(err) {
return Meteor.call('saveRoomSettings', room._id, RoomSettingsEnum.TOPIC, value, function(err) {
if (err) {
return handleError(err);
}

toastr.success(TAPi18n.__('Room_topic_changed_successfully'));
return RocketChat.callbacks.run('roomTopicChanged', room);
});
Expand All @@ -228,17 +230,18 @@ Template.channelSettings.onCreated(function() {
announcement: {
type: 'markdown',
label: 'Announcement',
canView() {
return true;
canView(room) {
return RocketChat.roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.ANNOUNCEMENT);
},
canEdit(room) {
return RocketChat.authz.hasAllPermission('edit-room', room._id);
},
save(value, room) {
return Meteor.call('saveRoomSettings', room._id, 'roomAnnouncement', value, function(err) {
return Meteor.call('saveRoomSettings', room._id, RoomSettingsEnum.ANNOUNCEMENT, value, function(err) {
if (err) {
return handleError(err);
}

toastr.success(TAPi18n.__('Room_announcement_changed_successfully'));
return RocketChat.callbacks.run('roomAnnouncementChanged', room);
});
Expand All @@ -248,16 +251,17 @@ Template.channelSettings.onCreated(function() {
type: 'text',
label: 'Description',
canView(room) {
return room.t !== 'd';
return RocketChat.roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.DESCRIPTION);
},
canEdit(room) {
return RocketChat.authz.hasAllPermission('edit-room', room._id);
},
save(value, room) {
return Meteor.call('saveRoomSettings', room._id, 'roomDescription', value, function(err) {
return Meteor.call('saveRoomSettings', room._id, RoomSettingsEnum.DESCRIPTION, value, function(err) {
if (err) {
return handleError(err);
}

return toastr.success(TAPi18n.__('Room_description_changed_successfully'));
});
}
Expand All @@ -278,7 +282,7 @@ Template.channelSettings.onCreated(function() {
}
},
canView(room) {
if (['c', 'p'].includes(room.t) === false) {
if (!['c', 'p'].includes(room.t)) {
return false;
} else if (room.t === 'p' && !RocketChat.authz.hasAllPermission('create-c')) {
return false;
Expand Down Expand Up @@ -332,17 +336,18 @@ Template.channelSettings.onCreated(function() {
isToggle: true,
processing: new ReactiveVar(false),
canView(room) {
return room.t !== 'd';
return RocketChat.roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.READ_ONLY);
},
canEdit(room) {
return RocketChat.authz.hasAllPermission('set-readonly', room._id);
},
save(value, room) {
this.processing.set(true);
return Meteor.call('saveRoomSettings', room._id, 'readOnly', value, (err) => {
return Meteor.call('saveRoomSettings', room._id, RoomSettingsEnum.READ_ONLY, value, (err) => {
if (err) {
return handleError(err);
}

this.processing.set(false);
return toastr.success(TAPi18n.__('Read_only_changed_successfully'));
});
Expand All @@ -354,7 +359,7 @@ Template.channelSettings.onCreated(function() {
isToggle: true,
processing: new ReactiveVar(false),
canView(room) {
return room.t !== 'd' && room.ro;
return RocketChat.roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.REACT_WHEN_READ_ONLY) && room.ro;
},
canEdit(room) {
return RocketChat.authz.hasAllPermission('set-react-when-readonly', room._id);
Expand All @@ -365,6 +370,7 @@ Template.channelSettings.onCreated(function() {
if (err) {
return handleError(err);
}

this.processing.set(false);
return toastr.success(TAPi18n.__('React_when_read_only_changed_successfully'));
});
Expand All @@ -376,7 +382,7 @@ Template.channelSettings.onCreated(function() {
isToggle: true,
processing: new ReactiveVar(false),
canView(room) {
return room.t !== 'd';
return RocketChat.roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.ARCHIVE_OR_UNARCHIVE);
},
canEdit(room) {
return RocketChat.authz.hasAtLeastOnePermission(['archive-room', 'unarchive-room'], room._id);
Expand All @@ -400,13 +406,15 @@ Template.channelSettings.onCreated(function() {
swal.enableButtons();
handleError(err);
}

swal({
title: value ? t('Room_archived') : t('Room_has_been_archived'),
text: value ? t('Room_has_been_archived') : t('Room_has_been_unarchived'),
type: 'success',
timer: 2000,
showConfirmButton: false
});

return RocketChat.callbacks.run(action, room);
});
} else {
Expand All @@ -421,7 +429,7 @@ Template.channelSettings.onCreated(function() {
showingValue: new ReactiveVar(false),
realValue: null,
canView(room) {
return room.t === 'c' && RocketChat.authz.hasAllPermission('edit-room', room._id);
return RocketChat.roomTypes.roomTypes[room.t].allowRoomSettingChange(room, RoomSettingsEnum.JOIN_CODE) && RocketChat.authz.hasAllPermission('edit-room', room._id);
},
canEdit(room) {
return RocketChat.authz.hasAllPermission('edit-room', room._id);
Expand Down Expand Up @@ -462,6 +470,7 @@ Template.channelSettings.onCreated(function() {
if (err) {
return handleError(err);
}

toastr.success(TAPi18n.__('Room_password_changed_successfully'));
return RocketChat.callbacks.run('roomCodeChanged', room);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

RocketChat.saveRoomName = function(rid, displayName, user, sendMessage = true) {
const room = RocketChat.models.Rooms.findOneById(rid);
if (room.t !== 'c' && room.t !== 'p') {
if (RocketChat.roomTypes.roomTypes[room.t].preventRenaming()) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
'function': 'RocketChat.saveRoomdisplayName'
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* globals RocketChatTabBar */
import s from 'underscore.string';

import { RocketChatTabBar } from 'meteor/rocketchat:lib';

Template.adminSounds.helpers({
isReady() {
if (Template.instance().ready != null) {
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-emoji-custom/admin/adminEmoji.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* globals RocketChatTabBar */
import s from 'underscore.string';

import { RocketChatTabBar } from 'meteor/rocketchat:lib';

Template.adminEmoji.helpers({
isReady() {
if (Template.instance().ready != null) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading