Skip to content

Commit

Permalink
fix: Fix sending Kudos from space Stream - MEED-3071 - Meeds-io/meeds…
Browse files Browse the repository at this point in the history
…#1435 (#449)

Prior to this change, when sending a kudos from space stream, the kudos wasn't sent. This change will allow to send kudos without attached entity type/id, which is the case in this specific usage. In fact, the error was mainly due to having used `spaceId` instead of `spacePrettyName` for space stream owner detection (replace `spacePrettyName: this.audience?.remoteId || this.spaceId` by `spacePrettyName: this.audience?.remoteId || this.spacePrettyName`).
  • Loading branch information
boubaker authored and rdenarie committed Dec 11, 2023
1 parent 5183c00 commit e449c4e
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.exoplatform.kudos.model;

public enum KudosEntityType {
ACTIVITY, COMMENT, USER_PROFILE, USER_TIPTIP, SPACE_PROFILE, SPACE_TIPTIP
ACTIVITY, COMMENT, USER_PROFILE, USER_TIPTIP, SPACE_PROFILE, SPACE_TIPTIP, NONE
}
3 changes: 3 additions & 0 deletions kudos-webapps/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
<depends>
<module>extensionRegistry</module>
</depends>
<depends>
<module>commonVueComponents</module>
</depends>
</module>

</gatein-resources>
2 changes: 1 addition & 1 deletion kudos-webapps/src/main/webapp/vue-app/js/KudosIdentity.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function getReceiver(entityType, entityId) {
console.error('Error retrieving activity details with id', entityId, e);
});
} else {
console.error('Unkown entity type', entityType, entityId);
return Promise.resolve();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export default {
document.dispatchEvent(new CustomEvent('displayTopBarLoading'));
return this.$kudosService.deleteKudos(event.detail).catch(e => {
if (e.message === 'KudosAlreadyLinked') {
document.dispatchEvent(new CustomEvent('notification-alert', {detail: {
message: this.$t('kudos.cancel.error.alreadyLinked'),
type: 'error',
document.dispatchEvent(new CustomEvent('alert-message', {detail: {
alertMessage: this.$t('kudos.cancel.error.alreadyLinked'),
alertType: 'error',
}}));
}})
.finally(() => document.dispatchEvent(new CustomEvent('hideTopBarLoading')));
Expand Down
189 changes: 96 additions & 93 deletions kudos-webapps/src/main/webapp/vue-app/kudos/components/KudosApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<kudos-api ref="kudosAPI" />

<exo-drawer
ref="activityKudosDrawer"
ref="drawer"
v-model="drawer"
v-draggable="enabled"
width="500px"
Expand Down Expand Up @@ -176,7 +176,7 @@
<div class="d-flex flex-row pt-8">
<rich-editor
v-if="drawer"
:ref="ckEditorId"
ref="kudosContent"
v-model="kudosMessage"
:max-length="MESSAGE_MAX_LENGTH"
:ck-editor-type="ckEditorType"
Expand Down Expand Up @@ -210,7 +210,7 @@
<v-btn
class="btn me-2"
:aria-label="$t('Confirmation.label.Cancel')"
@click="$refs.activityKudosDrawer.close()">
@click="$refs.drawer.close()">
{{ $t('Confirmation.label.Cancel') }}
</v-btn>
<v-btn
Expand Down Expand Up @@ -273,11 +273,19 @@ export default {
readOnlySpace: false,
username: eXo.env.portal.userName,
spaceId: eXo.env.portal.spaceId,
spacePrettyName: eXo.env.portal.spaceName,
audienceChoice: null,
noReceiverIdentityId: false
};
},
watch: {
error() {
if (this.error) {
this.displayAlert(this.error, 'error');
} else {
this.closeAlert();
}
},
listDialog() {
if (!this.listDialog || !this.entityId || !this.entityType) {
return;
Expand Down Expand Up @@ -460,94 +468,87 @@ export default {
this.error = null;
this.requiredField = false;
let kudosToSend = null;
if (this.entityId && this.entityType) {
this.allKudos = this.allKudosSent.slice(0);
if (this.remainingKudos > 0) {
return getReceiver(this.entityType, this.entityId)
.then(receiverDetails => {
this.noReceiverIdentityId = false;
if (receiverDetails && receiverDetails.id && receiverDetails.type) {
receiverDetails.isUserType = receiverDetails.type === 'organization' || receiverDetails.type === 'user';
if (!receiverDetails.isUserType || receiverDetails.id !== this.username) {
if (this.isLinkedKudos) {
this.selectedReceiver = {
receiverId: receiverDetails.id,
id: `organization:${receiverDetails.id}`,
identityId: receiverDetails.identityId,
profile: {
fullName: receiverDetails.fullname,
avatarUrl: receiverDetails.avatar,
external: receiverDetails.external === 'true',
},
providerId: 'organization',
remoteId: receiverDetails.id
};
} else {
this.identity = receiverDetails;
}
this.receiverId = receiverDetails.id;
this.receiverType = receiverDetails.type;
const receiverId = receiverDetails.id;
kudosToSend = {
receiverId: receiverId,
receiverType: receiverDetails.type,
avatar: receiverDetails.avatar,
profileUrl: `${eXo.env.portal.context}/${eXo.env.portal.portalName}/profile/${receiverId}`,
receiverIdentityId: receiverDetails.identityId,
receiverURL: receiverDetails.isUserType ? `/portal/intranet/profile/${receiverDetails.id}` : `/portal/g/:spaces:${receiverDetails.id}`,
receiverFullName: receiverDetails.fullname,
isCurrent: true
this.allKudos = this.allKudosSent.slice(0);
if (this.remainingKudos > 0) {
return (this.entityId && this.entityType && getReceiver(this.entityType, this.entityId) || Promise.resolve(null))
.then(receiverDetails => {
this.noReceiverIdentityId = !receiverDetails;
if (receiverDetails?.id && receiverDetails?.type) {
receiverDetails.isUserType = receiverDetails.type === 'organization' || receiverDetails.type === 'user';
if (!receiverDetails.isUserType || receiverDetails.id !== this.username) {
if (this.isLinkedKudos) {
this.selectedReceiver = {
receiverId: receiverDetails.id,
id: `organization:${receiverDetails.id}`,
identityId: receiverDetails.identityId,
profile: {
fullName: receiverDetails.fullname,
avatarUrl: receiverDetails.avatar,
external: receiverDetails.external === 'true',
},
providerId: 'organization',
remoteId: receiverDetails.id
};
if (receiverDetails.entityId) {
this.entityId = receiverDetails.entityId;
} else {
this.noReceiverIdentityId = true;
if (!receiverDetails.identityId) {
this.selectedReceiver = null;
}
}
if (receiverDetails.notAuthorized) {
this.error = this.$t('exoplatform.kudos.warning.userNotAuthorizedToReceiveKudos');
} else {
this.kudosToSend = kudosToSend;
}
this.allKudos.push(kudosToSend);
if (this.remainingKudos > 1) {
this.allKudos.push({});
} else {
this.identity = receiverDetails;
}
this.receiverId = receiverDetails.id;
this.receiverType = receiverDetails.type;
const receiverId = receiverDetails.id;
kudosToSend = {
receiverId: receiverId,
receiverType: receiverDetails.type,
avatar: receiverDetails.avatar,
profileUrl: `${eXo.env.portal.context}/${eXo.env.portal.portalName}/profile/${receiverId}`,
receiverIdentityId: receiverDetails.identityId,
receiverURL: receiverDetails.isUserType ? `/portal/intranet/profile/${receiverDetails.id}` : `/portal/g/:spaces:${receiverDetails.id}`,
receiverFullName: receiverDetails.fullname,
isCurrent: true
};
if (receiverDetails.entityId) {
this.entityId = receiverDetails.entityId;
} else {
this.noReceiverIdentityId = true;
if (!receiverDetails.identityId) {
this.selectedReceiver = null;
}
this.$nextTick(() => {
if ($('.kudosIconContainerTop.kudosIconContainerCurrent').length) {
$('.kudosIconContainerTop.kudosIconContainerCurrent')[0].scrollIntoView();
}
});
}
if (receiverDetails.notAuthorized) {
this.error = this.$t('exoplatform.kudos.warning.userNotAuthorizedToReceiveKudos');
} else {
this.entityOwner = null;
this.kudosToSend = kudosToSend;
}
this.allKudos.push(kudosToSend);
if (this.remainingKudos > 1) {
this.allKudos.push({});
}
} else {
this.entityOwner = null;
console.error('Receiver not found for entity type/id', this.entityType, this.entityId, receiverDetails);
throw new Error(this.$t('exoplatform.kudos.error.errorGettingReceiverInformation'));
return this.$nextTick().then(() => {
if ($('.kudosIconContainerTop.kudosIconContainerCurrent').length) {
$('.kudosIconContainerTop.kudosIconContainerCurrent')[0].scrollIntoView();
}
});
}
})
.catch(e => {
this.error = String(e);
console.error('Error retrieving entity details with type and id', this.entityType, this.entityId, e);
});
}
}
this.entityOwner = null;
})
.catch(e => {
this.error = String(e);
console.error('Error retrieving entity details with type and id', this.entityType, this.entityId, e);
});
}
},
refreshLink(element, entityType, entityId) {
if (this.ignoreRefresh) {
return Promise.resolve(null);
}
this.$refs.activityKudosDrawer.startLoading();
this.$refs.drawer.startLoading();
return getEntityKudos(entityType, entityId)
.then(kudosList => {
const $sendKudosLink = $(window.parentToWatch).find(`#SendKudosButton${entityType}${entityId}`);
$sendKudosLink.data('kudosList', kudosList);
this.kudosList = kudosList;
})
.finally(() => this.$refs.activityKudosDrawer.endLoading()
.finally(() => this.$refs.drawer.endLoading()
);
},
openDrawer(event) {
Expand All @@ -556,25 +557,24 @@ export default {
this.loading = true;
this.$nextTick(() => {
this.readOnlySpace = event?.detail?.readOnlySpace;
this.entityType = event && event.detail && event.detail.type;
this.entityId = event && event.detail && event.detail.id;
this.metadataObjectId = null;
this.entityOwner = event && event.detail && event.detail.owner;
this.parentEntityId = event && event.detail && event.detail.parentId;
this.entityType = event?.detail?.type || 'NONE';
this.entityId = event?.detail?.id || 0;
this.entityOwner = event?.detail?.owner || eXo.env.portal.userName;
this.parentEntityId = event?.detail?.parentId || '';
this.ignoreRefresh = event && event.detail && event.detail.ignoreRefresh;
this.spaceURL = event && event.detail && event.detail.spaceURL || null;
this.$refs.activityKudosDrawer.open();
this.$refs.activityKudosDrawer.startLoading();
this.initDrawer()
.then(() => this.$nextTick())
this.metadataObjectId = null;
this.$refs.drawer.open();
this.$refs.drawer.startLoading();
Promise.resolve(this.initDrawer())
.finally(() => this.$nextTick())
.then(() => this.ckEditorInstance.initCKEditor())
.finally( () => {
this.loading = false;
this.$refs.activityKudosDrawer.endLoading();
this.$refs.drawer.endLoading();
});
});
}
else {
} else {
this.displayAlert(this.$t('exoplatform.kudos.info.noKudosLeft', {
0: this.remainingDaysToReset,
1: this.remainingPeriodLabel
Expand All @@ -586,15 +586,15 @@ export default {
this.error = null;
const kudosMessage = this.ckEditorInstance.getMessage();
this.$refs.activityKudosDrawer.startLoading();
this.$refs.drawer.startLoading();
const kudos = {
entityType: this.entityType,
entityId: this.entityId,
parentEntityId: this.parentEntityId,
receiverType: this.receiverType || 'user',
receiverId: this.receiverId,
message: kudosMessage,
spacePrettyName: this.audience?.remoteId || this.spaceId
spacePrettyName: this.audience?.remoteId || this.spacePrettyName,
};
sendKudos(kudos)
.then(kudosSent => {
Expand Down Expand Up @@ -622,15 +622,15 @@ export default {
this.selectedReceiver = null;
this.resetAudienceChoice();
this.noReceiverIdentityId = false;
this.$refs.activityKudosDrawer.close();
this.$refs.drawer.close();
this.displayAlert(this.$t('exoplatform.kudos.success.kudosSent'));
})
.catch(e => {
console.error('Error refreshing UI', e);
this.error = String(e);
})
.finally(() => {
this.$refs.activityKudosDrawer.endLoading();
this.$refs.drawer.endLoading();
});
},
getRemainingDays() {
Expand All @@ -650,10 +650,13 @@ export default {
this.openSentKudos();
}
},
closeAlert() {
document.dispatchEvent(new CustomEvent('close-alert-message'));
},
displayAlert(message, type) {
document.dispatchEvent(new CustomEvent('notification-alert', {detail: {
message,
type: type || 'success',
document.dispatchEvent(new CustomEvent('alert-message', {detail: {
alertMessage: message,
alertType: type || 'success',
}}));
},
resetAudienceChoice() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ export default {
methods: {
openSendKudosDrawer() {
document.dispatchEvent(new CustomEvent('exo-kudos-open-send-modal', {detail: {
id: eXo.env.portal.userIdentityId,
type: 'USER_PROFILE',
parentId: '',
owner: eXo.env.portal.userName,
spaceURL: eXo.env.portal.spaceUrl,
readOnlySpace: eXo.env.portal.spaceUrl ? true : false
}}));
Expand Down

0 comments on commit e449c4e

Please sign in to comment.