Skip to content

Commit

Permalink
Merge pull request #4 from bhardwajaditya/service-account-settings
Browse files Browse the repository at this point in the history
Service Accounts Settings And Configuration Files
  • Loading branch information
bizzbyster authored Jun 5, 2019
2 parents 132ed10 + a4eb682 commit 8b5a9b5
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/service-accounts/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import './startup';
import './route';

// views
import './views/serviceAccountDashboard';
14 changes: 14 additions & 0 deletions app/service-accounts/client/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';

import { t } from '../../utils';

FlowRouter.route('/admin/serviceaccount', {
name: 'admin-serviceaccount',
action() {
return BlazeLayout.render('main', {
center: 'serviceAccountDashboard',
pageTitle: t('Service_account_applied'),
});
},
});
11 changes: 11 additions & 0 deletions app/service-accounts/client/startup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AdminBox } from '../../ui-utils';
import { hasAtLeastOnePermission } from '../../authorization';

AdminBox.addOption({
icon: 'discover',
href: 'admin/serviceaccount',
i18nLabel: 'Service_account_dashboard',
permissionGranted() {
return hasAtLeastOnePermission(['view-service-account-request']);
},
});
88 changes: 88 additions & 0 deletions app/service-accounts/client/views/serviceAccountDashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<template name="serviceAccountDashboard">
<div class="main-content-flex">
<section class="page-container page-home page-static page-settings content-background-color">
{{> header sectionName=pageTitle}}
<div class="content">
{{#unless hasPermission}}
<p>{{_ "You_are_not_authorized_to_view_this_page"}}</p>
{{else}}
<div class="results">
{{{_ "Showing_results" users.length}}}
</div>
{{#table fixed='true' onItemClick=onTableItemClick onScroll=onTableScroll onResize=onTableResize}}
<thead>
<tr>
<th width="34%">
<div class="table-fake-th">{{_ "Name"}}</div>
</th>
<th width="33%">
<div class="table-fake-th">{{_ "Username"}}</div>
</th>
<th width="33%">
<div class="table-fake-th">{{_ "Email"}}</div>
</th>
<th width="33%">
<div class="table-fake-th">{{_ "Roles"}}</div>
</th>
<th width="33%">
<div class="table-fake-th">{{_ "Status"}}</div>
</th>
</tr>
</thead>
<tbody>
{{#each users}}
<tr class='user-info'>
<td width="30%">
<div class="rc-table-wrapper">
<div class="rc-table-avatar">
{{> avatar username=username}}
</div>
<div class="rc-table-info">
<span class="rc-table-title">{{name}}</span>
</div>
</div>
</td>
<td width="20%">
<div class="rc-table-wrapper">
<div class="rc-table-info">
<span class="rc-table-title">{{username}}</span>
</div>
</div>
</td>
<td width="20%">
<div class="rc-table-wrapper">
<div class="rc-table-info">
<span class="rc-table-title">{{emailAddress}}</span>
</div>
</div>
</td>
<td width="10%">
<div class="rc-table-wrapper">
<div class="rc-table-info">
<span class="rc-table-title">{{roles}}</span>
</div>
</div>
</td>
<td width="20%">
<div class="rc-table-wrapper">{{#if not active}}{{_"deactivated"}}{{else}}{{status}}{{/if}}</div>
</td>
</tr>
{{else}} {{# with searchText}}
<tr class="table-no-click">
<td>{{_ "No_results_found_for"}} {{.}}</td>
</tr>
{{/with}} {{/each}} {{#unless isReady}}
<tr class="table-no-click">
<td class="table-loading-td" colspan="{{#if showLastMessage}}5{{else}}4{{/if}}">{{> loading}}</td>
</tr>
{{/unless}}
</tbody>
{{/table}}
{{/unless}}
</div>
</section>
{{#with flexData}}
{{> flexTabBar}}
{{/with}}
</div>
</template>
104 changes: 104 additions & 0 deletions app/service-accounts/client/views/serviceAccountDashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';
import { Tracker } from 'meteor/tracker';
import _ from 'underscore';

import { t } from '../../../utils/client';
import { handleError } from '../../../utils/client/lib/handleError';
import { SideNav } from '../../../ui-utils';
import { modal } from '../../../ui-utils/client/lib/modal';
import { hasAllPermission } from '../../../authorization/client/hasPermission';
import FullUser from '../../../models/client/models/FullUser';
import './serviceAccountDashboard.html';

Template.serviceAccountDashboard.helpers({
isReady() {
const instance = Template.instance();
return instance.ready && instance.ready.get();
},
users() {
return Template.instance().users();
},
hasPermission() {
return hasAllPermission('view-service-account-request');
},
hasUsers() {
return Template.instance().users() && Template.instance().users().count() > 0;
},
emailAddress() {
return _.map(this.emails, function(e) { return e.address; }).join(', ');
},
hasMore() {
const instance = Template.instance();
const users = instance.users();
if (instance.limit && instance.limit.get() && users && users.length) {
return instance.limit.get() === users.length;
}
},
});

Template.serviceAccountDashboard.events({
'click .user-info'(e) {
e.preventDefault();
modal.open({
title: t('Are_you_sure'),
text: t('The_user_s_will_be_allowed_to_create_service_accounts', this.username),
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: t('Yes'),
cancelButtonText: t('Cancel'),
closeOnConfirm: false,
html: false,
}, () => {
Meteor.call('authorization:removeUserFromRole', 'service-account-applied', this.username, null, function(error) {
if (error) {
return handleError(error);
}
});
Meteor.call('authorization:addUserToRole', 'service-account-approved', this.username, null, function(error) {
if (error) {
return handleError(error);
}

modal.open({
title: t('Added'),
text: t('User_added'),
type: 'success',
timer: 1000,
showConfirmButton: false,
});
});
});
},
});

Template.serviceAccountDashboard.onCreated(function() {
const instance = this;
this.limit = new ReactiveVar(50);
this.ready = new ReactiveVar(true);
this.filter = new ReactiveVar('');

this.autorun(() => {
const filter = instance.filter.get();
const limit = instance.limit.get();
const subscription = instance.subscribe('fullUserData', filter, limit);
instance.ready.set(subscription.ready());
});
this.users = function() {
const roles = [].concat('service-account-applied');
const query = {
roles: { $in: roles },
};
const limit = instance.limit && instance.limit.get();
return FullUser.find(query, { limit, sort: { username: 1, name: 1 } }).fetch();
};
});

Template.serviceAccountDashboard.onRendered(() => {
Tracker.afterFlush(() => {
SideNav.setFlex('adminFlex');
SideNav.openFlex();
});
});
18 changes: 18 additions & 0 deletions app/service-accounts/server/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Meteor } from 'meteor/meteor';

import { settings } from '../../settings';

Meteor.startup(() => {
settings.addGroup('Service Accounts', function() {
this.add('Service_account_enabled', true, {
group: 'Service Accounts',
i18nLabel: 'Enable',
type: 'boolean',
public: true,
});
this.add('Service_account_limit', 3, {
type: 'int',
public: true,
});
});
});
2 changes: 2 additions & 0 deletions app/service-accounts/server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './config';
import './permissions';
19 changes: 19 additions & 0 deletions app/service-accounts/server/permissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';

import { Roles, Permissions } from '../../models';

Meteor.startup(() => {
const roles = _.pluck(Roles.find().fetch(), 'name');
if (roles.indexOf('service-account-applied') === -1) {
Roles.createOrUpdate('service-account-applied');
}
if (roles.indexOf('service-account-approved') === -1) {
Roles.createOrUpdate('service-account-approved');
}
if (Permissions) {
Permissions.createOrUpdate('view-sa-request', ['admin']);
Permissions.createOrUpdate('create-service-account', ['service-account-approved', 'admin']);
Permissions.createOrUpdate('delete-service-account', ['admin']);
}
});
1 change: 1 addition & 0 deletions client/importPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import '../app/otr/client';
import '../app/push-notifications/client';
import '../app/apps/client';
import '../app/setup-wizard/client';
import '../app/service-accounts/client';
import '../app/slackbridge/client';
import '../app/slashcommands-archiveroom/client';
import '../app/slashcommand-asciiarts/client';
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,9 @@
"Server_Type": "Server Type",
"Service": "Service",
"Service_account_key": "Service account key",
"Service_account_applied": "User applications for creating Service Accounts",
"Service_account_dashboard": "Service Account Dashboard",
"Service_account_limit": "Service Accounts per user",
"set-leader": "Set Leader",
"set-moderator": "Set Moderator",
"set-moderator_description": "Permission to set other users as moderator of a channel",
Expand Down Expand Up @@ -2822,6 +2825,7 @@
"The_server_will_restart_in_s_seconds": "The server will restart in %s seconds",
"The_setting_s_is_configured_to_s_and_you_are_accessing_from_s": "The setting <strong>%s</strong> is configured to <strong>%s</strong> and you are accessing from <strong>%s</strong>!",
"The_user_will_be_removed_from_s": "The user will be removed from %s",
"The_user_s_will_be_allowed_to_create_service_accounts": "This user %s will be allowed to create Service Accounts",
"The_user_s_will_be_removed_from_role_s": "The user %s will be removed from role %s",
"The_user_wont_be_able_to_type_in_s": "The user won't be able to type in %s",
"Theme": "Theme",
Expand Down
1 change: 1 addition & 0 deletions server/importPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import '../app/push-notifications/server';
import '../app/retention-policy';
import '../app/apps/server';
import '../app/setup-wizard/server';
import '../app/service-accounts/server';
import '../app/slackbridge/server';
import '../app/slashcommands-archiveroom/server';
import '../app/slashcommand-asciiarts/server';
Expand Down

0 comments on commit 8b5a9b5

Please sign in to comment.