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

feat: Replace Web Notification rendering engine from gtmpl to Vue - EXO-66411 #40

Merged
merged 2 commits into from
Oct 16, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
import org.exoplatform.services.log.Log;
import org.exoplatform.services.organization.OrganizationService;
import org.exoplatform.services.organization.User;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
import org.exoplatform.social.notification.LinkProviderUtils;
import org.exoplatform.social.notification.Utils;

public class MfaAdminRevocationRequestPlugin extends BaseNotificationPlugin {

Expand All @@ -58,11 +62,19 @@ public String getId() {
@Override
public NotificationInfo makeNotification(NotificationContext ctx) {
String userId = ctx.value(MfaNotificationUtils.MFA_REVOCATION_REQUEST_REQUESTER);
Identity identity =
Utils.getIdentityManager().getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId);
try {

List<String> recipients = getRecipients();


recipients.remove(userId);
return NotificationInfo.instance().key(getId())
.with("username", userId)
.with("fullname", identity.getProfile().getFullName())
.with("avatar", LinkProviderUtils.getUserAvatarUrl(identity.getProfile()))
.with("url", MfaNotificationUtils.getMfaAdminURL())
.to(recipients);
} catch (Exception e) {
ctx.setException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,51 @@
import org.exoplatform.commons.api.notification.annotation.TemplateConfig;
import org.exoplatform.commons.api.notification.annotation.TemplateConfigs;
import org.exoplatform.commons.api.notification.channel.template.AbstractTemplateBuilder;
import org.exoplatform.commons.api.notification.channel.template.TemplateProvider;
import org.exoplatform.commons.api.notification.model.MessageInfo;
import org.exoplatform.commons.api.notification.model.NotificationInfo;
import org.exoplatform.commons.api.notification.model.PluginKey;
import org.exoplatform.commons.api.notification.service.template.TemplateContext;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.mfa.notifications.plugin.MfaAdminRevocationRequestPlugin;
import org.exoplatform.mfa.notifications.utils.MfaNotificationUtils;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
import org.exoplatform.social.notification.Utils;

import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

@TemplateConfigs(templates = {
@TemplateConfig(pluginId = MfaAdminRevocationRequestPlugin.ID, template = "war:/notifications/templates/push/MfaAdminRevocationRequestPlugin.gtmpl")
})
public class PushTemplateProvider extends WebTemplateProvider {

private final Map<PluginKey, AbstractTemplateBuilder> webTemplateBuilders = new HashMap<>();
public class PushTemplateProvider extends TemplateProvider {

public PushTemplateProvider(InitParams initParams) {
super(initParams);
this.webTemplateBuilders.putAll(this.templateBuilders);
this.templateBuilders.put(PluginKey.key(MfaAdminRevocationRequestPlugin.ID), mfaRevocationRequest);
this.templateBuilders.put(PluginKey.key(MfaAdminRevocationRequestPlugin.ID), new TemplateBuilder());
}

/** Defines the template builder for MfaRevocationRequestPlugin*/
private AbstractTemplateBuilder mfaRevocationRequest = new AbstractTemplateBuilder() {

private class TemplateBuilder extends AbstractTemplateBuilder {
@Override
protected MessageInfo makeMessage(NotificationContext ctx) {
MessageInfo messageInfo = webTemplateBuilders.get(new PluginKey(MfaAdminRevocationRequestPlugin.ID)).buildMessage(ctx);
NotificationInfo notification = ctx.getNotificationInfo();
String language = getLanguage(notification);
TemplateContext
templateContext = TemplateContext.newChannelInstance(getChannelKey(), notification.getKey().getId(), language);
Identity identity =
Utils.getIdentityManager().getOrCreateIdentity(OrganizationIdentityProvider.NAME, notification.getValueOwnerParameter(
"username"));
templateContext.put("USER", Utils.addExternalFlag(identity));
ctx.setException(templateContext.getException());

MessageInfo messageInfo = new MessageInfo();
return messageInfo.subject(MfaNotificationUtils.getMfaAdminURL()).end();
}

@Override
protected boolean makeDigest(NotificationContext ctx, Writer writer) {
return false;
}
};
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ Notification.mail.MfaAdminRevocationRequestPlugin.Hello=Hello
Notification.intranet.message.MfaAdminRevocationRequestPlugin={0} has sent a request to revoke his authentification key
Notification.mail.MfaAdminRevocationRequestPlugin.administration=MFA Administration page
Notification.mail.MfaAdminRevocationRequestPlugin.footer=eXo Platform

Notification.label.types.security=Security
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Notification.mail.MfaAdminRevocationRequestPlugin.Hello=Bonjour
Notification.intranet.message.MfaAdminRevocationRequestPlugin={0} a envoy\u00E9 une demande de r\u00E9vocation de sa cl\u00E9 d'authentification
Notification.mail.MfaAdminRevocationRequestPlugin.administration=Page d'administration de MFA
Notification.mail.MfaAdminRevocationRequestPlugin.footer=eXoPlatform
Notification.label.types.security=S\u00E9curit\u00E9
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,6 @@

<external-component-plugins>
<target-component>org.exoplatform.commons.api.notification.channel.ChannelManager</target-component>
<component-plugin>
<name>web.channel.mfa.template</name>
<set-method>registerTemplateProvider</set-method>
<type>org.exoplatform.mfa.notifications.provider.WebTemplateProvider</type>
<init-params>
<value-param>
<name>channel-id</name>
<value>WEB_CHANNEL</value>
</value-param>
</init-params>
</component-plugin>
<component-plugin>
<name>mail.channel.mfa.template</name>
<set-method>registerTemplateProvider</set-method>
Expand Down
20 changes: 20 additions & 0 deletions webapps/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,24 @@
</depends>
</module>
</portlet>

<module>
<name>mfaNotificationExtension</name>
<load-group>notificationGRP</load-group>
<script>
<path>/js/notificationExtension.bundle.js</path>
</script>
<depends>
<module>vue</module>
</depends>
<depends>
<module>vuetify</module>
</depends>
<depends>
<module>eXoVueI18n</module>
</depends>
<depends>
<module>extensionRegistry</module>
</depends>
</module>
</gatein-resources>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!--
Copyright (C) 2023 eXo Platform SAS.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<user-notification-template
:notification="notification"
:avatar-url="avatarUrl"
:message="message"
:url="url"
user-avatar />
</template>
<script>
export default {
props: {
notification: {
type: Object,
default: null,
},
},
computed: {
url() {
//we keep both possibility so that old notifications, generated before the current modification are still ok
return this.notification?.parameters?.url || `/portal/g/:platform:administrators/multifactor-authentication`;
},
avatarUrl() {
//we keep both possibility so that old notifications, generated before the current modification are still ok
return this.notification?.parameters?.avatar || `/portal/rest/v1/social/users/${this.notification?.parameters?.username}/avatar`;
},
message() {
const creator = this.notification?.parameters?.fullname;
return this.$t('Notification.intranet.message.MfaAdminRevocationRequestPlugin', {
0: `<a class="user-name font-weight-bold">${creator}</a>`
});
}
}
};
</script>
30 changes: 30 additions & 0 deletions webapps/src/main/webapp/vue-apps/mfa-notifications/extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2023 eXo Platform SAS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <gnu.org/licenses>.
*/

extensionRegistry.registerExtension('WebNotification', 'notification-group-extension', {
rank: 100,
name: 'security',
plugins: [
'MfaAdminRevocationRequestPlugin',
],
icon: 'fa-shield-alt',
});
extensionRegistry.registerExtension('WebNotification', 'notification-content-extension', {
type: 'MfaAdminRevocationRequestPlugin',
rank: 10,
vueComponent: Vue.options.components['user-notification-mfa-revocation'],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2023 eXo Platform SAS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <gnu.org/licenses>.
*/

import MfaAdminRevocationRequestPlugin from './components/MfaAdminRevocationRequestPlugin.vue';

const components = {
'user-notification-mfa-revocation': MfaAdminRevocationRequestPlugin,
};

for (const key in components) {
Vue.component(key, components[key]);
}
Loading