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] Service account transfer #17

Open
wants to merge 14 commits into
base: service-accounts
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions app/lib/server/functions/notifications/serviceAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { metrics } from '../../../../metrics';
import { Notifications } from '../../../../notifications';

export function shouldNotifyServiceAccountOwner({
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser,
hasReplyToThread,
roomType,
}) {
return roomType === 'd' || hasMentionToAll || hasMentionToHere || isHighlighted || hasMentionToUser || hasReplyToThread;
}

export function notifyServiceAccountOwner(receiver, ownerId, message, room) {
metrics.notificationsSent.inc({ notification_type: 'sa' });
Notifications.notifyUser(ownerId, 'sa-notification', {
payload: {
_id: message._id,
rid: message.rid,
sender: message.u,
receiver: receiver.username,
type: room.t,
name: room.name,
},
});
}
14 changes: 14 additions & 0 deletions app/lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { sendEmail, shouldNotifyEmail } from '../functions/notifications/email';
import { sendSinglePush, shouldNotifyMobile } from '../functions/notifications/mobile';
import { notifyDesktopUser, shouldNotifyDesktop } from '../functions/notifications/desktop';
import { notifyAudioUser, shouldNotifyAudio } from '../functions/notifications/audio';
import { notifyServiceAccountOwner, shouldNotifyServiceAccountOwner } from '../functions/notifications/serviceAccount';

export const sendNotification = async ({
subscription,
Expand Down Expand Up @@ -46,6 +47,7 @@ export const sendNotification = async ({
status: 1,
statusConnection: 1,
username: 1,
u: 1,
},
}),
];
Expand Down Expand Up @@ -149,6 +151,17 @@ export const sendNotification = async ({
return false;
});
}

if (receiver.u && shouldNotifyServiceAccountOwner({
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser,
hasReplyToThread,
roomType,
})) {
notifyServiceAccountOwner(receiver, receiver.u._id, message, room);
}
};

const project = {
Expand All @@ -168,6 +181,7 @@ const project = {
'receiver.status': 1,
'receiver.statusConnection': 1,
'receiver.username': 1,
'receiver.u': 1,
},
};

Expand Down
14 changes: 14 additions & 0 deletions app/models/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,20 @@ export class Users extends Base {
return this.update(query, update, { multi: true });
}

setOwnerByServiceAccountUsername(serviceAccount, newOwner) {
const query = {
username: serviceAccount,
};

const update = {
$set: {
u: newOwner,
},
};

return this.update(query, update);
}

// INSERT
create(data) {
const user = {
Expand Down
4 changes: 3 additions & 1 deletion app/service-accounts/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import './route';
import './views/serviceAccountDashboard';
import './views/creationDialog/createServiceAccount';
import './views/serviceAccountsList';
import './views/serviceAccountSidebarLogin';
import './views/accountServiceAccounts';
import './views/serviceAccountTransfer';

import '../lib/serviceAccountRoomType';
import './views/serviceAccountSidebarLogin';
43 changes: 43 additions & 0 deletions app/service-accounts/client/stylesheets/serviceAccounts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.rc-service-account-list {
&__user {

display: flex;

padding: 8px 0;

cursor: pointer;
align-items: center;

&.active,
&:hover {
background-color: #eeeeee;

& .rc-member-list__menu {
opacity: 1;
}
}

& > .avatar {
width: var(--sidebar-account-thumb-size);
height: var(--sidebar-account-thumb-size);
}
}

&__username {
display: flex;
flex: 1 1 auto;

margin: 0 12px 0 8px;

font-size: 16px;
align-items: center;
}

&__username-alert {
font-weight: bold;
}
}

.service-account-notification {
color: var(--rc-color-alert-message-primary-background);
}
76 changes: 76 additions & 0 deletions app/service-accounts/client/views/accountServiceAccounts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<template name="accountServiceaccounts">
<div class="main-content-flex">
<section class="page-container page-home page-static page-settings content-background-color">
{{> header sectionName="Your Service Accounts"}}
<div class="content">
<div class="results">
{{{_ "Showing_results" users.length}}}
</div>
{{#table fixed='true' onScroll=onTableScroll onResize=onTableResize}}
<thead>
<tr>
<th width="20%">
<div class="table-fake-th">{{_ "Name"}}</div>
</th>
<th width="20%">
<div class="table-fake-th">{{_ "Username"}}</div>
</th>
<th width="40%">
<div class="table-fake-th">{{_ "Description"}}</div>
</th>
<th width="10%">
<div class="table-fake-th">{{_ "Transfer"}}</div>
</th>
</tr>
</thead>
<tbody>
{{#unless hasServiceAccounts}}
<tr>
<td colspan="5" class="empty-role">{{_ "You_have_no_service_accounts"}}</td>
</tr>
{{/unless}}
{{#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">{{username}}</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="40%">
<div class="rc-table-wrapper">
<div class="rc-table-info">
<span class="rc-table-title">{{description}}</span>
</div>
</div>
</td>
<td width="10%">
<div class="rc-table-wrapper">
<div class="rc-table-info">
<span class="rc-table-title"><a class="js-transfer">{{_"Transfer"}}</a></span>
</div>
</div>
</td>
</tr>
{{/each}} {{#unless loading}}
<tr class="table-no-click">
<td class="table-loading-td" colspan="{{#if showLastMessage}}5{{else}}4{{/if}}">{{> loading}}</td>
</tr>
{{/unless}}
</tbody>
{{/table}}
</div>
</section>
</div>
</template>
58 changes: 58 additions & 0 deletions app/service-accounts/client/views/accountServiceAccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { Meteor } from 'meteor/meteor';

import './accountServiceAccounts.html';
import { t, handleError } from '../../../utils';
import { modal } from '../../../ui-utils';

Template.accountServiceaccounts.helpers({
loading() {
return Template.instance().loading.get();
},
users() {
return Template.instance().users.get();
},
hasServiceAccounts() {
return Template.instance().users.get() && Template.instance().users.get().length > 0;
},
});

Template.accountServiceaccounts.events({
'click .js-transfer'(e) {
e.preventDefault();
modal.open({
title: t('Service_account_transfer'),
content: 'serviceAccountTransfer',
data: {
onCreate() {
modal.close();
},
serviceAccount: this.username,
},
modifier: 'modal',
showConfirmButton: false,
showCancelButton: false,
confirmOnEnter: false,
});
},
});


Template.accountServiceaccounts.onCreated(function() {
const instance = this;
this.ready = new ReactiveVar(true);
this.users = new ReactiveVar([]);
this.loading = new ReactiveVar(true);
this.autorun(() => {
instance.loading.set(true);
Meteor.call('getLinkedServiceAccounts', function(err, serviceAccounts) {
if (err) {
instance.loading.set(false);
return handleError(err);
}
instance.users.set(serviceAccounts);
instance.loading.set(false);
});
});
});
49 changes: 31 additions & 18 deletions app/service-accounts/client/views/serviceAccountSidebarLogin.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
<template name="serviceAccountSidebarLogin">
<div class="rc-popover__column">
<ul class="rc-popover__list">
{{#if showOwnerAccountLink}}
<p>Go back to main account</p>
<li class='rc-member-list__user js-login'>
{{> avatar username=owner.username}}
<div class="rc-member-list__username">
{{owner.username}}
</div>
</li>
{{#if loading}}
<p>Loading ... </p>
{{else}}
{{#if hasServiceAccounts}}
{{#each users}}
<li class='rc-member-list__user js-login'>
{{> avatar username=username}}
<div class="rc-member-list__username">
{{username}}
</div>
</li>
{{/each}}
{{#if showOwnerAccountLink}}
<p>Go back to main account</p>
<li class='rc-service-account-list__user js-login'>
{{> avatar username=owner.username}}
<div class="rc-service-account-list__username">
{{owner.username}}
</div>
</li>
{{else}}
<p>{{_ "You_have_no_service_accounts"}}</p>
{{#if hasServiceAccounts}}
{{#each users}}
<li class='rc-service-account-list__user js-login'>
{{> avatar username=username}}
<div class="rc-service-account-list__username">
{{#if receivedNewMessage username}}
<span class="rc-service-account-list__username-alert">
{{username}}
</span>
{{else}}
{{username}}
{{/if}}
</div>
<div class="badge">
{{unread}}
</div>
</li>
{{/each}}
{{else}}
<p>{{_ "You_have_no_service_accounts"}}</p>
{{/if}}
{{/if}}
{{/if}}
</ul>
Expand Down
Loading