Merge pull request 'feat: colleciton delete' (#15) from feat/collection-delete into main
Some checks failed
Renovate / renovate (push) Failing after 1m13s
Some checks failed
Renovate / renovate (push) Failing after 1m13s
Reviewed-on: #15
This commit was merged in pull request #15.
This commit is contained in:
@@ -549,7 +549,7 @@ class DefaultController extends ControllerAbstract {
|
|||||||
throw new InvalidArgumentException(self::ERR_INVALID_IDENTIFIER);
|
throw new InvalidArgumentException(self::ERR_INVALID_IDENTIFIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mailManager->collectionDelete(
|
$result = $this->mailManager->collectionDelete(
|
||||||
$tenantId,
|
$tenantId,
|
||||||
$userId,
|
$userId,
|
||||||
$data['provider'],
|
$data['provider'],
|
||||||
@@ -557,6 +557,48 @@ class DefaultController extends ControllerAbstract {
|
|||||||
$data['identifier'],
|
$data['identifier'],
|
||||||
$data['options'] ?? []
|
$data['options'] ?? []
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (is_bool($result)) {
|
||||||
|
return [
|
||||||
|
'outcome' => 'deleted'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result instanceof JsonSerializable) {
|
||||||
|
return [
|
||||||
|
'outcome' => 'moved',
|
||||||
|
'data' => $result
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function collectionMove(string $tenantId, string $userId, array $data): mixed {
|
||||||
|
if (!isset($data['target'])) {
|
||||||
|
throw new InvalidArgumentException(self::ERR_MISSING_TARGET);
|
||||||
|
}
|
||||||
|
if (!is_string($data['target'])) {
|
||||||
|
throw new InvalidArgumentException(self::ERR_INVALID_TARGET);
|
||||||
|
}
|
||||||
|
if (!isset($data['sources'])) {
|
||||||
|
throw new InvalidArgumentException(self::ERR_MISSING_SOURCES);
|
||||||
|
}
|
||||||
|
if (!is_array($data['sources'])) {
|
||||||
|
throw new InvalidArgumentException(self::ERR_INVALID_SOURCES);
|
||||||
|
}
|
||||||
|
|
||||||
|
$target = ResourceIdentifier::fromString($data['target']);
|
||||||
|
if (!$target instanceof CollectionIdentifier) {
|
||||||
|
throw new InvalidArgumentException('Invalid parameter: target must be provider:service:collection');
|
||||||
|
}
|
||||||
|
|
||||||
|
$source = ResourceIdentifier::fromArray($data['source']);
|
||||||
|
if (!$source instanceof CollectionIdentifier) {
|
||||||
|
throw new InvalidArgumentException('Invalid parameter: sources must contain provider:service:collection identifiers');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->mailManager->collectionMove($tenantId, $userId, $target, $source);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== Entity Operations ====================
|
// ==================== Entity Operations ====================
|
||||||
|
|||||||
@@ -653,7 +653,7 @@ class Manager {
|
|||||||
*
|
*
|
||||||
* @return CollectionBaseInterface|null
|
* @return CollectionBaseInterface|null
|
||||||
*/
|
*/
|
||||||
public function collectionDelete(string $tenantId, ?string $userId, string $providerId, string|int $serviceId, string|int $collectionId, array $options = []): bool {
|
public function collectionDelete(string $tenantId, ?string $userId, string $providerId, string|int $serviceId, string|int $collectionId, array $options = []): CollectionBaseInterface | bool {
|
||||||
// retrieve service
|
// retrieve service
|
||||||
$service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId);
|
$service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId);
|
||||||
|
|
||||||
@@ -666,10 +666,9 @@ class Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$force = $options['force'] ?? false;
|
$force = $options['force'] ?? false;
|
||||||
$recursive = $options['recursive'] ?? false;
|
|
||||||
|
|
||||||
// delete collection
|
// delete collection
|
||||||
return $service->collectionDelete($collectionId, $force, $recursive);
|
return $service->collectionDelete($collectionId, $force);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== Message Operations ====================
|
// ==================== Message Operations ====================
|
||||||
|
|||||||
@@ -123,8 +123,14 @@ export const collectionService = {
|
|||||||
*
|
*
|
||||||
* @returns Promise with deletion result
|
* @returns Promise with deletion result
|
||||||
*/
|
*/
|
||||||
async delete(request: CollectionDeleteRequest): Promise<CollectionDeleteResponse> {
|
async delete(request: CollectionDeleteRequest): Promise<boolean | CollectionObject> {
|
||||||
return await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
|
const response = await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
|
||||||
|
|
||||||
|
if (response.outcome === 'moved' && response.data) {
|
||||||
|
return createCollectionObject(response.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import type {
|
|||||||
EntityStreamRequest,
|
EntityStreamRequest,
|
||||||
EntityStreamResponse,
|
EntityStreamResponse,
|
||||||
} from '../types/entity';
|
} from '../types/entity';
|
||||||
import type { EntityIdentifier } from '../types/common';
|
|
||||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||||
import { EntityObject } from '../models';
|
import { EntityObject } from '../models';
|
||||||
|
|
||||||
|
|||||||
@@ -385,12 +385,16 @@ export const useCollectionsStore = defineStore('mailCollectionsStore', () => {
|
|||||||
*
|
*
|
||||||
* @returns Promise with deletion result
|
* @returns Promise with deletion result
|
||||||
*/
|
*/
|
||||||
async function remove(provider: string, service: string | number, identifier: string | number): Promise<any> {
|
async function remove(provider: string, service: string | number, identifier: string | number): Promise<CollectionObject | boolean> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
await collectionService.delete({ provider, service, identifier })
|
const response = await collectionService.delete({ provider, service, identifier })
|
||||||
|
|
||||||
|
if (response !== true && !(response instanceof CollectionObject)) {
|
||||||
|
console.warn('[Mail Manager][Store] - Delete failed. Received unexpected response from delete operation:', response)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Remove deleted collection from state
|
|
||||||
const key = identifierKey(provider, service, identifier)
|
const key = identifierKey(provider, service, identifier)
|
||||||
const previousCollection = _collections.value[key]
|
const previousCollection = _collections.value[key]
|
||||||
|
|
||||||
@@ -400,7 +404,19 @@ export const useCollectionsStore = defineStore('mailCollectionsStore', () => {
|
|||||||
|
|
||||||
delete _collections.value[key]
|
delete _collections.value[key]
|
||||||
|
|
||||||
|
if (response instanceof CollectionObject) {
|
||||||
|
const movedCollection = response
|
||||||
|
const movedKey = identifierKey(movedCollection.provider, movedCollection.service, movedCollection.identifier)
|
||||||
|
|
||||||
|
_collections.value[movedKey] = movedCollection
|
||||||
|
indexCollection(movedCollection)
|
||||||
|
|
||||||
|
console.debug('[Mail Manager][Store] - Successfully moved collection to trash', key, '->', movedKey)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
console.debug('[Mail Manager][Store] - Successfully deleted collection:', key)
|
console.debug('[Mail Manager][Store] - Successfully deleted collection:', key)
|
||||||
|
return response
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('[Mail Manager][Store] - Failed to delete collection:', error)
|
console.error('[Mail Manager][Store] - Failed to delete collection:', error)
|
||||||
throw error
|
throw error
|
||||||
|
|||||||
@@ -124,5 +124,6 @@ export interface CollectionDeleteRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface CollectionDeleteResponse {
|
export interface CollectionDeleteResponse {
|
||||||
success: boolean;
|
outcome: 'deleted' | 'moved';
|
||||||
|
data?: CollectionInterface | null; // If moved, the new location of the collection
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user