feat(AppConfig): iterate how apps are managed

- auth clients are always shared, cannot be disabled
- custom connections are enabled by default, can be disabled
- any existing connections can be reconnected regardless of its AppConfig or AppAuthClient states
This commit is contained in:
Ali BARIN
2024-12-09 17:46:51 +00:00
parent 00e80f1fba
commit a57134a89c
48 changed files with 192 additions and 563 deletions

View File

@@ -33,10 +33,6 @@ class Connection extends Base {
},
};
static get virtualAttributes() {
return ['reconnectable'];
}
static relationMappings = () => ({
user: {
relation: Base.BelongsToOneRelation,
@@ -83,18 +79,6 @@ class Connection extends Base {
},
});
get reconnectable() {
if (this.appAuthClientId) {
return this.appAuthClient.active;
}
if (this.appConfig) {
return !this.appConfig.disabled && this.appConfig.customConnectionAllowed;
}
return true;
}
encryptData() {
if (!this.eligibleForEncryption()) return;
@@ -144,19 +128,13 @@ class Connection extends Base {
);
}
if (!appConfig.customConnectionAllowed && this.formattedData) {
if (appConfig.useOnlyPredefinedAuthClients && this.formattedData) {
throw new NotAuthorizedError(
`New custom connections have been disabled for ${app.name}!`
);
}
if (!appConfig.shared && this.appAuthClientId) {
throw new NotAuthorizedError(
'The connection with the given app auth client is not allowed!'
);
}
if (appConfig.shared && !this.formattedData) {
if (!this.formattedData) {
const authClient = await appConfig
.$relatedQuery('appAuthClients')
.findById(this.appAuthClientId)