From fe2d0945ca4cfb04eafdac2607940913ade435ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lindo=C3=A9lio=20L=C3=A1zaro?= Date: Tue, 24 Oct 2017 09:40:49 -0200 Subject: [PATCH] Add tokenpass art in channel title bar --- packages/rocketchat-i18n/i18n/en.i18n.json | 1 + packages/rocketchat-tokenpass/client/styles.css | 12 ++++++++++++ packages/rocketchat-tokenpass/package.js | 2 ++ .../server/methods/getChannelTokenpass.js | 17 +++++++++++++++++ .../rocketchat-ui/client/views/app/room.html | 4 ++++ packages/rocketchat-ui/client/views/app/room.js | 14 ++++++++++++++ 6 files changed, 50 insertions(+) create mode 100644 packages/rocketchat-tokenpass/client/styles.css create mode 100644 packages/rocketchat-tokenpass/server/methods/getChannelTokenpass.js diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 1b9d358cf883..646a05ab44e6 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -1825,6 +1825,7 @@ "Token_Access": "Token Access", "Token_Controlled_Access": "Token Controlled Access", "Token_required": "Token required", + "Tokenpass_Channel_Label": "Tokenpass Channel", "Tokenpass_Channels": "Tokenpass Channels", "Tokens_Minimum_Needed_Balance": "Minimum needed token balance", "Tokens_Minimum_Needed_Balance_Description": "Set minimum needed balance on each token. Blank or \"0\" for not limit.", diff --git a/packages/rocketchat-tokenpass/client/styles.css b/packages/rocketchat-tokenpass/client/styles.css new file mode 100644 index 000000000000..126731991bd7 --- /dev/null +++ b/packages/rocketchat-tokenpass/client/styles.css @@ -0,0 +1,12 @@ +.icon-tokenpass { + display: inline-block; + + width: 24px; + height: 0.8em; + + margin-bottom: -1px; + + background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0MzIgMzgxLjUiPjxkZWZzPjxzdHlsZT4uY2x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repeat: no-repeat; + background-position: center center; +} diff --git a/packages/rocketchat-tokenpass/package.js b/packages/rocketchat-tokenpass/package.js index 431807b0361e..f111d2f32486 100644 --- a/packages/rocketchat-tokenpass/package.js +++ b/packages/rocketchat-tokenpass/package.js @@ -20,6 +20,7 @@ Package.onUse(function(api) { api.addFiles('client/login-button.css', 'client'); api.addFiles('client/channelSettings.css', 'client'); + api.addFiles('client/styles.css', 'client'); api.addFiles('client/startup.js', 'client'); api.addFiles('client/roomType.js', 'client'); @@ -42,6 +43,7 @@ Package.onUse(function(api) { api.addFiles('server/models/Users.js', 'server'); api.addFiles('server/methods/findTokenChannels.js', 'server'); + api.addFiles('server/methods/getChannelTokenpass.js', 'server'); api.addFiles('server/cronRemoveUsers.js', 'server'); diff --git a/packages/rocketchat-tokenpass/server/methods/getChannelTokenpass.js b/packages/rocketchat-tokenpass/server/methods/getChannelTokenpass.js new file mode 100644 index 000000000000..feb94a53f3b7 --- /dev/null +++ b/packages/rocketchat-tokenpass/server/methods/getChannelTokenpass.js @@ -0,0 +1,17 @@ +Meteor.methods({ + getChannelTokenpass(rid) { + check(rid, String); + + if (!Meteor.userId()) { + throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getChannelTokenpass' }); + } + + const room = RocketChat.models.Rooms.findOneById(rid); + + if (!room) { + throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'getChannelTokenpass' }); + } + + return room.tokenpass; + } +}); diff --git a/packages/rocketchat-ui/client/views/app/room.html b/packages/rocketchat-ui/client/views/app/room.html index c32d010129d1..2b99839f5b29 100644 --- a/packages/rocketchat-ui/client/views/app/room.html +++ b/packages/rocketchat-ui/client/views/app/room.html @@ -15,6 +15,10 @@

{{/if}} + {{#if tokenAccessChannel}} + + {{/if}} + {{> icon block="room-icon" icon=roomIcon classes=userStatus}} {{roomName}} diff --git a/packages/rocketchat-ui/client/views/app/room.js b/packages/rocketchat-ui/client/views/app/room.js index 6fa33dab5788..5447f9f6e5df 100644 --- a/packages/rocketchat-ui/client/views/app/room.js +++ b/packages/rocketchat-ui/client/views/app/room.js @@ -207,6 +207,10 @@ Template.room.helpers({ return roomIcon; }, + tokenAccessChannel() { + return Template.instance().hasTokenpass.get(); + }, + userStatus() { const roomData = Session.get(`roomData${ this._id }`); return RocketChat.roomTypes.getUserStatus(roomData.t, this._id) || 'offline'; @@ -768,6 +772,16 @@ Template.room.onCreated(function() { return this.userDetail.set(null); }; + this.hasTokenpass = new ReactiveVar(false); + + if (RocketChat.settings.get('API_Tokenpass_URL') !== '') { + Meteor.call('getChannelTokenpass', this.data._id, (error, result) => { + if (!error) { + this.hasTokenpass.set(!!(result && result.tokens && result.tokens.length > 0)); + } + }); + } + Meteor.call('getRoomRoles', this.data._id, function(error, results) { if (error) { return handleError(error);