fix: Fix automatic credential selection when credentials are shared (#5020)

* fix: fix default credentials when inserting nodes

* fix: update default without sharing

* fix: fix clearing credential bug, automatically selecting shared cred bug

* fix: include sharable creds in automatic selections

* fix: update getter

* fix: refactor subscribe logic, fix update bug

* fix: remove unnessary import

* format: prettier
This commit is contained in:
Mutasem Aldmour
2022-12-23 16:32:06 +01:00
committed by GitHub
parent 4651147096
commit 6a8448da5f
4 changed files with 94 additions and 44 deletions

View File

@@ -72,6 +72,22 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
{},
);
},
allUsableCredentialsByType(): { [type: string]: ICredentialsResponse[] } {
const credentials = this.allCredentials;
const types = this.allCredentialTypes;
const usersStore = useUsersStore();
return types.reduce(
(accu: { [type: string]: ICredentialsResponse[] }, type: ICredentialType) => {
accu[type.name] = credentials.filter((cred: ICredentialsResponse) => {
return cred.type === type.name && usersStore.isResourceAccessible(cred);
});
return accu;
},
{},
);
},
getCredentialTypeByName() {
return (type: string): ICredentialType => this.credentialTypes[type];
},
@@ -89,6 +105,11 @@ export const useCredentialsStore = defineStore(STORES.CREDENTIALS, {
return this.allCredentialsByType[credentialType] || [];
};
},
getUsableCredentialByType() {
return (credentialType: string): ICredentialsResponse[] => {
return this.allUsableCredentialsByType[credentialType] || [];
};
},
getNodesWithAccess() {
return (credentialTypeName: string) => {
const nodeTypesStore = useNodeTypesStore();

View File

@@ -18,14 +18,16 @@ import {
validatePasswordToken,
validateSignupToken,
} from '@/api/users';
import { PERSONALIZATION_MODAL_KEY, STORES } from '@/constants';
import { EnterpriseEditionFeature, PERSONALIZATION_MODAL_KEY, STORES } from '@/constants';
import {
ICredentialsResponse,
IInviteResponse,
IPersonalizationLatestVersion,
IUser,
IUserResponse,
IUsersState,
} from '@/Interface';
import { getCredentialPermissions } from '@/permissions';
import { getPersonalizedNodeTypes, isAuthorized, PERMISSIONS, ROLE } from '@/utils';
import { defineStore } from 'pinia';
import Vue from 'vue';
@@ -90,6 +92,13 @@ export const useUsersStore = defineStore(STORES.USERS, {
}
return getPersonalizedNodeTypes(answers);
},
isResourceAccessible() {
return (resource: ICredentialsResponse): boolean => {
const permissions = getCredentialPermissions(this.currentUser, resource);
return permissions.use;
};
},
},
actions: {
addUsers(users: IUserResponse[]) {