forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from bhardwajaditya/service-account-settings
Service Accounts Settings And Configuration Files
- Loading branch information
Showing
11 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import './startup'; | ||
import './route'; | ||
|
||
// views | ||
import './views/serviceAccountDashboard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
88
app/service-accounts/client/views/serviceAccountDashboard.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
104
app/service-accounts/client/views/serviceAccountDashboard.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import './config'; | ||
import './permissions'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters