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

Merge Space Settings Review - Meeds-io/MIPs#147 #1739

Merged
merged 2 commits into from
Sep 26, 2024
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 @@ -51,44 +51,45 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<v-flex
xs12>
<v-list>
<template v-for="item in sort(spacesRequests)">
<v-list-item
:key="item.id"
class="py-0 px-2">
<v-list-item-avatar class="my-1 me-2" size="30">
<v-img :src="item.avatar" />
</v-list-item-avatar>
<v-list-item
v-for="item in sort(spacesRequests)"
:key="item.id"
class="py-0 px-2">
<v-list-item-avatar class="my-1 me-2" size="30">
<v-img :src="item.avatarUrl" />
</v-list-item-avatar>

<v-list-item-content class="py-0">
<v-list-item-title class="request-user-name darken-2" v-text="item.displayName" />
<v-list-item-subtitle v-sanitized-html="item.description" />
</v-list-item-content>
<v-list-item-action>
<v-btn-toggle
class="transparent"
dark>
<v-btn
text
icon
small
min-width="auto"
class="px-0 connexion-accept-btn"
@click="replyInvitationToJoinSpace(item.id, 'approved')">
<v-icon color="primary-color" size="20">mdi-checkbox-marked-circle</v-icon>
</v-btn>
<v-btn
text
icon
small
min-width="auto"
class="px-0 connexion-refuse-btn"
@click="replyInvitationToJoinSpace(item.id, 'ignored')">
<v-icon color="grey lighten-1" size="20">mdi-close-circle</v-icon>
</v-btn>
</v-btn-toggle>
</v-list-item-action>
</v-list-item>
</template>
<v-list-item-content class="py-0">
<v-list-item-title class="request-user-name darken-2" v-text="item.displayName" />
<v-list-item-subtitle v-sanitized-html="item.description" />
</v-list-item-content>
<v-list-item-action>
<v-btn-toggle
class="transparent"
dark>
<v-btn
:loading="saving"
text
icon
small
min-width="auto"
class="px-0 connexion-accept-btn"
@click="replyInvitationToJoinSpace(item, 'approved')">
<v-icon color="success" size="20">mdi-checkbox-marked-circle</v-icon>
</v-btn>
<v-btn
:loading="saving"
text
icon
small
min-width="auto"
class="px-0 connexion-refuse-btn"
@click="replyInvitationToJoinSpace(item, 'ignored')">
<v-icon color="error" size="20">mdi-close-circle</v-icon>
</v-btn>
</v-btn-toggle>
</v-list-item-action>
</v-list-item>
</v-list>
</v-flex>
<v-flex
Expand All @@ -109,49 +110,32 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</v-layout>
</template>
<script>
import {getSpacesRequests, replyInvitationToJoinSpace} from '../profilStatsAPI';
export default {
data() {
return {
spacesRequests: [],
spacesRequestsSize: '',
saving: false,
invitationSpaceUrl: `${eXo.env.portal.context}/${eXo.env.portal.metaPortalName}/spaces/receivedInvitations`
};
},
created(){
this.getSpacesRequests();
},

methods: {
getSpacesRequests() {
this.spacesRequests = [];
getSpacesRequests().then(
(data) => {
this.spacesRequestsSize = data.size;
this.$emit('showRequestsSpace', this.spacesRequestsSize);
if (this.spacesRequestsSize > 0) {
for (let i = 0; i < data.spacesMemberships.length; i++) {
const spaceRequest = {};
spaceRequest.id = data.spacesMemberships[i].id;
fetch(`${data.spacesMemberships[i].space}`, {
method: 'GET',
credentials: 'include',
}).then((resp) => {
if (resp?.ok) {
return resp.json();
}
else {
throw new Error ('Error when getting space');
}
}).then((data) => {
spaceRequest.avatar = data.avatarUrl || data.avatarUrl || `/portal/rest/v1/social/spaces/${spaceRequest.id.split(':')[0]}/avatar`;
spaceRequest.displayName = data.displayName;
this.spacesRequests.splice(i, 0, spaceRequest);
});
}
}
}
);
return this.$spaceService.getSpaceMemberships({
user: eXo.env.portal.userName,
status: 'invited',
expand: 'spaces',
returnSize: true,
limit: 3,
}).then((data) => {
this.spacesRequestsSize = data.size;
this.$emit('showRequestsSpace', this.spacesRequestsSize);
this.spacesRequests = data.spacesMemberships?.map?.(m => m.space);
});
},
sort(array) {
return array.slice().sort(function(a, b) {
Expand All @@ -161,21 +145,23 @@ export default {
openSpaceRequests() {
window.location.href = `${this.invitationSpaceUrl}`;
},
replyInvitationToJoinSpace(spaceId, reply) {
replyInvitationToJoinSpace(spaceId, reply)
.then(() => {
if (reply === 'approved') {
const confirmedRequest = this.spacesRequests.filter(request => request.id === spaceId)[0];
const space = {
id: confirmedRequest.id,
displayName: confirmedRequest.displayName,
avatarUrl: confirmedRequest.avatar,

};
this.$emit('invitationReplied', space);
}
this.getSpacesRequests();
});
async replyInvitationToJoinSpace(item, reply) {
this.saving = true;
try {
if (reply === 'approved') {
await this.$spaceService.accept(item.id);
this.$emit('invitationReplied', {
id: item.id,
displayName: item.displayName,
avatarUrl: item.avatarUrl,
});
} else if (reply === 'ignored') {
await this.$spaceService.deny(item.id);
}
this.getSpacesRequests();
} finally {
this.saving = false;
}
},
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</v-flex>
</template>
<script>
import {getUserInformations, getSpacesRequests, getConnectionsRequests, getGamificationPoints, getReputationStatus} from '../profilStatsAPI';
import {getUserInformations, getConnectionsRequests, getGamificationPoints, getReputationStatus} from '../profilStatsAPI';
export default {
props: {
commonsSpaceDefaultSize: {
Expand Down Expand Up @@ -214,9 +214,11 @@ export default {

this.profileUrl = this.profileUrl + (this.isCurrentUserProfile ? '' : `/${ eXo.env.portal.profileOwner}`);

this.loadingWidgets = 5;
this.loadingWidgets = this.isCurrentUserProfile && 5 || 4;
this.retrieveUserData().finally(() => this.loadingWidgets--);
this.getSpacesRequestsSize().finally(() => this.loadingWidgets--);
if (this.isCurrentUserProfile) {
this.getSpacesRequestsSize().finally(() => this.loadingWidgets--);
}
this.getConnectionsRequestsSize().finally(() => this.loadingWidgets--);
this.getGamificationRank().finally(() => this.loadingWidgets--);
this.getGamificationPoints().finally(() => this.loadingWidgets--);
Expand All @@ -240,7 +242,12 @@ export default {
});
},
getSpacesRequestsSize() {
return getSpacesRequests().then(
return this.$spaceService.getSpaceMemberships({
user: eXo.env.portal.userName,
status: 'invited',
returnSize: true,
limit: 1,
}).then(
(data) => {
this.spacesRequestsSize = data.size;
this.$emit('showRequestsSpace', this.spacesRequestsSize);
Expand Down
33 changes: 0 additions & 33 deletions portlets/src/main/webapp/vue-app/profileStats/profilStatsAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,6 @@ export function getCommonsSpaces(offset, limit) {
});
}

export function getSpacesRequests() {
return fetch( '/portal/rest/v1/social/spacesMemberships?status=invited&returnSize=true&limit=3', {
method: 'GET',
credentials: 'include',
}).then((resp) => {
if (resp?.ok) {
return resp.json();
}
else {
throw new Error ('Error when getting spaces requests');
}
});
}

export function getSuggestionsSpace(){
return fetch('/portal/rest/homepage/intranet/spaces/suggestions', {
credentials: 'include'
Expand All @@ -112,25 +98,6 @@ export function getSuggestionsSpace(){
});
}

export function replyInvitationToJoinSpace(spaceMembershipId, reply) {
const data = {status: `${reply}`};
return fetch(`/portal/rest/v1/social/spacesMemberships/${spaceMembershipId}`, {
method: 'PUT',
credentials: 'include',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
}).then((resp) => {
if (resp?.ok) {
return resp.json();
}
else {
throw new Error ('Error when replying invitation to join space');
}
});
}

export function getUserConnections(query, offset, limit, expand) {
return fetch(`${eXo.env.portal.context}/${eXo.env.portal.rest}/v1/social/users/${eXo.env.portal.profileOwner}/connections?q=${query || ''}&offset=${offset || 0}&limit=${limit|| 0}&expand=${expand || ''}&returnSize=true`, {
method: 'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,25 +513,13 @@ private boolean isProgramOwner(long spaceId,
}

private boolean isSpaceManager(long spaceId, String username) {
if (spaceService.isSuperManager(username)) {
return true;
}
Space space = spaceService.getSpaceById(String.valueOf(spaceId));
if (space == null) {
return false;
}
return spaceService.isManager(space, username);
return spaceService.canManageSpace(space, username);
}

private boolean isSpaceMember(long spaceId, String username) {
if (StringUtils.isBlank(username)) {
return false;
}
Space space = spaceService.getSpaceById(String.valueOf(spaceId));
if (space == null) {
return false;
}
return spaceService.isMember(space, username);
return spaceService.canViewSpace(space, username);
}

private boolean isSpaceOpen(long spaceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ public Identity getOrCreateIdentity(String providerId, String remoteId, boolean
.orElse(null);
}

public Identity getOrCreateSpaceIdentity(String spacePrettyName) {
return getOrCreateIdentity(SpaceIdentityProvider.NAME, spacePrettyName);
}

public Identity getOrCreateUserIdentity(String username) {
return getOrCreateIdentity(OrganizationIdentityProvider.NAME, username);
}

public Identity getIdentity(String identityId, boolean isProfileLoaded) {
return identities.stream()
.filter(identity -> StringUtils.equals(identity.getId(), identityId))
Expand Down
Loading