Skip to content

Commit

Permalink
Merge branch 'develop' into admin-embedded-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Apr 27, 2019
2 parents 21c2b32 + 67d07a2 commit a18c80d
Show file tree
Hide file tree
Showing 25 changed files with 491 additions and 61 deletions.
6 changes: 6 additions & 0 deletions app/apps/client/admin/apps.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
{{> icon icon="upload" block="rc-icon--default-size"}} {{_ "Upload app"}}
</button>
{{/if}}

{{#unless cloudLoggedIn}}
<button class="rc-button rc-button--small rc-button--primary rc-button--outline" data-button="login">
{{> icon icon="cloud-plus" block="rc-icon--default-size"}} {{_ "Login"}}
</button>
{{/unless}}
{{/header}}
<div class="rc-table-content">
{{>tabs tabs=tabsData}}
Expand Down
48 changes: 47 additions & 1 deletion app/apps/client/admin/apps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import toastr from 'toastr';
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Template } from 'meteor/templating';
Expand Down Expand Up @@ -63,6 +64,17 @@ const getInstalledApps = async (instance) => {
}
};

const getCloudLoggedIn = async (instance) => {
Meteor.call('cloud:checkUserLoggedIn', (error, result) => {
if (error) {
console.warn(error);
return;
}

instance.cloudLoggedIn.set(result);
});
};

Template.apps.onCreated(function() {
const instance = this;
this.ready = new ReactiveVar(false);
Expand All @@ -77,6 +89,7 @@ Template.apps.onCreated(function() {
this.end = new ReactiveVar(false);
this.isLoading = new ReactiveVar(true);
this.searchType = new ReactiveVar('marketplace');
this.cloudLoggedIn = new ReactiveVar(false);

const queryTab = FlowRouter.getQueryParam('tab');
if (queryTab) {
Expand All @@ -103,6 +116,8 @@ Template.apps.onCreated(function() {
// });
};

getCloudLoggedIn(instance);

instance.onAppRemoved = function _appOnAppRemoved(appId) {
const apps = instance.apps.get();

Expand Down Expand Up @@ -151,6 +166,9 @@ Template.apps.helpers({
appsDevelopmentMode() {
return settings.get('Apps_Framework_Development_Mode') === true;
},
cloudLoggedIn() {
return Template.instance().cloudLoggedIn.get();
},
parseStatus(status) {
return t(`App_status_${ status }`);
},
Expand Down Expand Up @@ -270,6 +288,9 @@ Template.apps.events({
'click [data-button="install"]'() {
FlowRouter.go('/admin/app/install');
},
'click [data-button="login"]'() {
FlowRouter.go('/admin/cloud');
},
'click .js-install'(e, template) {
e.stopPropagation();
const elm = e.currentTarget.parentElement;
Expand Down Expand Up @@ -298,6 +319,26 @@ Template.apps.events({

const rl = this;

if (!template.cloudLoggedIn.get()) {
modal.open({
title: t('Apps_Marketplace_Login_Required_Title'),
text: t('Apps_Marketplace_Login_Required_Description'),
type: 'info',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Login'),
cancelButtonText: t('Cancel'),
closeOnConfirm: true,
html: false,
}, function(confirmed) {
if (confirmed) {
FlowRouter.go('/admin/cloud');
}
return;
});
return;
}

// play animation
const elm = e.currentTarget.parentElement;

Expand Down Expand Up @@ -328,7 +369,12 @@ Template.apps.events({
});
})
.catch((e) => {
toastr.error((e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message);
const errMsg = (e.xhr.responseJSON && e.xhr.responseJSON.error) || e.message;
toastr.error(errMsg);

if (errMsg === 'Unauthorized') {
getCloudLoggedIn(template);
}
});
},
'keyup .js-search'(e, t) {
Expand Down
10 changes: 8 additions & 2 deletions app/apps/server/communication/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HTTP } from 'meteor/http';
import { API } from '../../../api/server';
import Busboy from 'busboy';

import { getWorkspaceAccessToken } from '../../../cloud/server';
import { getWorkspaceAccessToken, getUserCloudAccessToken } from '../../../cloud/server';
import { settings } from '../../../settings';
import { Info } from '../../../utils';

Expand Down Expand Up @@ -94,7 +94,13 @@ export class AppsRestApi {

if (this.queryParams.buildBuyUrl && this.queryParams.appId) {
const workspaceId = settings.get('Cloud_Workspace_Id');
return API.v1.success({ url: `${ baseUrl }/apps/${ this.queryParams.appId }/buy?workspaceId=${ workspaceId }` });

const token = getUserCloudAccessToken(this.getLoggedInUser()._id, true, 'marketplace:purchase', false);
if (!token) {
return API.v1.failure({ error: 'Unauthorized' });
}

return API.v1.success({ url: `${ baseUrl }/apps/${ this.queryParams.appId }/buy?workspaceId=${ workspaceId }&token=${ token }` });
}

const apps = manager.get().map((prl) => {
Expand Down
69 changes: 54 additions & 15 deletions app/cloud/client/admin/cloud.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<template name="cloud">
<div class="main-content-flex">
<section class="page-container page-home page-static page-settings">
{{> header sectionName="Cloud_connect"}}
{{#header sectionName="Cloud_connect" hideHelp=true fixedHeight=true fullpage=true}}
<button type="button" class="rc-button rc-button--primary action cloud-console-btn">{{_ "Cloud_console"}}</button>
{{/header}}
<div class="content">
{{#requiresPermission 'manage-cloud'}}
<div class="section">

<div class="section-title">
<div class="section-title-text">
{{_ "Cloud_what_is_it"}}
Expand All @@ -14,29 +17,41 @@
<div class="section-content">
<p>{{_ "Cloud_what_is_it_description"}}</p>
</div>

<details>
<div class="section-content">
<p>{{_ "Cloud_what_is_it_services_like"}}</p>
<ul style="list-style-type:disc;margin-left:15px;">
<li>{{_ "Register_Server_Registered_Push_Notifications"}}</li>
<li>{{_ "Register_Server_Registered_Livechat"}}</li>
<li>{{_ "Register_Server_Registered_OAuth"}}</li>
<li>{{_ "Register_Server_Registered_Marketplace"}}</li>
</ul>
</div>
<div class="section-content">
{{_ "Cloud_what_is_it_additional"}}
</div>
</details>
</div>
<div class="section">
{{#if info.connectToCloud}}
{{#if info.workspaceRegistered}}
<div class="section-content border-component-color">
<p>{{_ "Cloud_workspace_connected"}}</p>
<div class="input-line double-col">
<label class="setting-label" title=""></label>
<div class="setting-field">
<a href="https://cloud.rocket.chat" class="rc-button rc-button--primary" target="_blank">{{_ "Cloud_login_to_cloud"}}</a>
</div>
</div>
</div>

<div class="section-content border-component-color">
<p>{{_ "Cloud_workspace_support"}}</p>
<div class="input-line double-col">
{{#if isLoggedIn}}
<label class="setting-label" title=""></label>
<div class="setting-field">
<button type="button" class="rc-button rc-button--danger action sync-btn">{{_ "Sync"}}</button>
<button type="button" class="rc-button rc-button--primary action logout-btn" target="_blank">{{_ "Cloud_logout"}}</button>
</div>
</div>
{{else}}
<label class="setting-label" title=""></label>
<div class="setting-field">
<button type="button" class="rc-button rc-button--primary action login-btn" target="_blank">{{_ "Cloud_login_to_cloud"}}</button>
</div>
{{/if}}
</div>
</div>

<div class="section-content border-component-color">
<p>{{_ "Cloud_workspace_disconnect"}}</p>
Expand All @@ -59,7 +74,8 @@
<div class="input-line double-col">
<label class="setting-label" title=""></label>
<div class="setting-field">
<button type="button" class="rc-button rc-button--primary action update-email-btn">{{_ "Cloud_update_email"}}</button>
<button type="button" class="rc-button rc-button--primary action update-email-btn" style="float:left">{{_ "Cloud_update_email"}}</button>
<button type="button" class="rc-button rc-button--primary action resend-email-btn" style="float:left;margin-left:5px;">{{_ "Cloud_resend_email"}}</button>
</div>
</div>

Expand All @@ -77,7 +93,7 @@
</div>
</div>

<p>If you still haven't received a registration email please make sure your email is updated above. If you still have issues you can contact support at: <a href="mailto:support@rocket.chat?subject=[Self Hosted Registration]&body=WorkspaceId: {{ info.workspaceId }}%0D%0ADeployment Id: {{ info.uniqueId }}%0D%0AIssue: <please describe your issue here>">support@rocket.chat</a></p>
<p>{{_ "Cloud_connect_support"}}: <a href="mailto:support@rocket.chat?subject=[Self Hosted Registration]&body=WorkspaceId: {{ info.workspaceId }}%0D%0ADeployment Id: {{ info.uniqueId }}%0D%0AIssue: <please describe your issue here>">support@rocket.chat</a></p>
</div>
{{/if}}
{{else}}
Expand All @@ -92,6 +108,29 @@
</div>
{{/if}}
</div>
{{#if info.connectToCloud}}
<div class="section">
<div class="section-title">
<div class="section-title-text">
{{_ "Cloud_troubleshooting"}}
</div>
</div>

<div class="section-content border-component-color">
<p>{{_ "Cloud_workspace_support"}}</p>
<div class="input-line double-col">
<label class="setting-label" title=""></label>
<div class="setting-field">
<button type="button" class="rc-button rc-button--danger action sync-btn">{{_ "Sync"}}</button>
</div>
</div>
</div>

<div class="section-content">
{{_ "Cloud_status_page_description"}}: <a href="https://status.rocket.chat" target="_blank">status.rocket.chat</a>
</div>
</div>
{{/if}}
{{/requiresPermission}}
</div>
</section>
Expand Down
70 changes: 66 additions & 4 deletions app/cloud/client/admin/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Template.cloud.onCreated(function() {
const instance = this;
instance.info = new ReactiveVar();
instance.loading = new ReactiveVar(true);
instance.isLoggedIn = new ReactiveVar(false);

instance.loadRegStatus = function _loadRegStatus() {
Meteor.call('cloud:checkRegisterStatus', (error, info) => {
Expand All @@ -27,6 +28,39 @@ Template.cloud.onCreated(function() {
});
};

instance.getLoggedIn = function _getLoggedIn() {
Meteor.call('cloud:checkUserLoggedIn', (error, result) => {
if (error) {
console.warn(error);
return;
}

instance.isLoggedIn.set(result);
});
};

instance.oauthAuthorize = function _oauthAuthorize() {
Meteor.call('cloud:getOAuthAuthorizationUrl', (error, url) => {
if (error) {
console.warn(error);
return;
}

window.location.href = url;
});
};

instance.logout = function _logout() {
Meteor.call('cloud:logout', (error) => {
if (error) {
console.warn(error);
return;
}

instance.getLoggedIn();
});
};

instance.connectWorkspace = function _connectWorkspace(token) {
Meteor.call('cloud:connectWorkspace', token, (error, success) => {
if (error) {
Expand Down Expand Up @@ -101,9 +135,7 @@ Template.cloud.onCreated(function() {
return;
}

toastr.success(t('Connected'));

instance.loadRegStatus();
return instance.syncWorkspace();
});
};

Expand All @@ -114,19 +146,24 @@ Template.cloud.onCreated(function() {
} else {
instance.loadRegStatus();
}

instance.getLoggedIn();
});

Template.cloud.helpers({
info() {
return Template.instance().info.get();
},
isLoggedIn() {
return Template.instance().isLoggedIn.get();
},
});

Template.cloud.events({
'click .update-email-btn'() {
const val = $('input[name=cloudEmail]').val();

Meteor.call('cloud:updateEmail', val, (error) => {
Meteor.call('cloud:updateEmail', val, false, (error) => {
if (error) {
console.warn(error);
return;
Expand All @@ -136,6 +173,27 @@ Template.cloud.events({
});
},

'click .resend-email-btn'() {
const val = $('input[name=cloudEmail]').val();

Meteor.call('cloud:updateEmail', val, true, (error) => {
if (error) {
console.warn(error);
return;
}

toastr.success(t('Requested'));
});
},

'click .login-btn'(e, i) {
i.oauthAuthorize();
},

'click .logout-btn'(e, i) {
i.logout();
},

'click .connect-btn'(e, i) {
const token = $('input[name=cloudToken]').val();

Expand All @@ -153,6 +211,10 @@ Template.cloud.events({
'click .sync-btn'(e, i) {
i.syncWorkspace();
},

'click .cloud-console-btn'() {
window.location.href = 'https://cloud.rocket.chat';
},
});

Template.cloud.onRendered(() => {
Expand Down
2 changes: 1 addition & 1 deletion app/cloud/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FlowRouter.route('/admin/cloud/oauth-callback', {
AdminBox.addOption({
icon: 'cloud-plus',
href: 'admin/cloud',
i18nLabel: 'Cloud',
i18nLabel: 'Cloud Connect',
permissionGranted() {
return hasAtLeastOnePermission(['manage-cloud']);
},
Expand Down
Loading

0 comments on commit a18c80d

Please sign in to comment.