Skip to content
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 @@ -161,11 +161,13 @@ export class SettingsAddonsComponent {

readonly filteredAddonCards = computed(() => {
const searchValue = this.searchValue().toLowerCase();
return this.currentAddonsState().filter(
const filteredAddons = this.currentAddonsState().filter(
(card) =>
card.externalServiceName.toLowerCase().includes(searchValue) ||
card.displayName.toLowerCase().includes(searchValue)
);

return sortAddonCardsAlphabetically(filteredAddons);
});

onCategoryChange(value: Primitive): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ export class AddonCardComponent {

if (!isConfigured) return true;

return hasAdmin;
const addon = this.card();
if (!addon) return true;

let isOwner = false;
if ('configuredAddon' in addon && addon.configuredAddon) {
isOwner = addon.configuredAddon.currentUserIsOwner;
} else if ('currentUserIsOwner' in addon) {
isOwner = addon.currentUserIsOwner;
}

return hasAdmin || isOwner;
});

readonly buttonLabel = computed(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/app/shared/enums/operation-names.enum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export enum OperationNames {
LIST_ROOT_ITEMS = 'list_root_items',
LIST_CHILD_ITEMS = 'list_child_items',
LIST_ROOT_COLLECTIONS = 'list_root_collections',
LIST_COLLECTION_ITEMS = 'list_collection_items',
GET_ITEM_INFO = 'get_item_info',
HAS_REVISIONS = 'has_revisions',
}
10 changes: 8 additions & 2 deletions src/app/shared/services/addons/addon-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ export class AddonFormService {
: (addon as AddonModel).id;
}

private getOperationNames(addonTypeString: string): string[] {
return addonTypeString === AddonType.CITATION
? ['list_collection_items', 'list_root_collections', 'get_item_info']
: ['list_child_items', 'list_root_items', 'get_item_info'];
}

generateConfiguredAddonCreatePayload(
addon: AddonModel | AuthorizedAccountModel,
selectedAccount: AuthorizedAccountModel,
Expand All @@ -132,7 +138,7 @@ export class AddonFormService {
display_name: displayName,
...(addonTypeString !== AddonType.LINK && { root_folder: selectedStorageItemId }),
connected_capabilities: ['UPDATE', 'ACCESS'],
connected_operation_names: ['list_child_items', 'list_root_items', 'get_item_info'],
connected_operation_names: this.getOperationNames(addonTypeString),
external_service_name: addon.externalServiceName,
...(resourceType && { resource_type: resourceType }),
...(addonTypeString === AddonType.LINK && { target_id: selectedStorageItemId }),
Expand Down Expand Up @@ -180,7 +186,7 @@ export class AddonFormService {
authorized_resource_uri: resourceUri,
display_name: displayName,
connected_capabilities: ['UPDATE', 'ACCESS'],
connected_operation_names: ['list_child_items', 'list_root_items', 'get_item_info'],
connected_operation_names: this.getOperationNames(addonTypeString),
external_service_name: addon.externalServiceName,
...(resourceType && { resource_type: resourceType }),
...(addonTypeString !== AddonType.LINK && { root_folder: selectedStorageItemId }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
import { Injectable } from '@angular/core';

import { OperationNames } from '@osf/shared/enums';
import { isCitationAddon } from '@osf/shared/helpers';
import { AuthorizedAccountModel, ConfiguredAddonModel, OperationInvocationRequestJsonApi } from '@shared/models';

@Injectable({
providedIn: 'root',
})
export class AddonOperationInvocationService {
private getAddonSpecificOperationName(
operationName: OperationNames,
addon: AuthorizedAccountModel | ConfiguredAddonModel
): OperationNames {
if (!isCitationAddon(addon)) {
return operationName;
}

const operationMap: Record<string, OperationNames> = {
[OperationNames.LIST_ROOT_ITEMS]: OperationNames.LIST_ROOT_COLLECTIONS,
[OperationNames.LIST_CHILD_ITEMS]: OperationNames.LIST_COLLECTION_ITEMS,
};

return operationMap[operationName] ?? operationName;
}

createInitialOperationInvocationPayload(
operationName: OperationNames,
selectedAccount: AuthorizedAccountModel,
itemId?: string
): OperationInvocationRequestJsonApi {
const operationKwargs = this.getOperationKwargs(operationName, itemId);
const addonSpecificOperationName = this.getAddonSpecificOperationName(operationName, selectedAccount);
const operationKwargs = this.getOperationKwargs(addonSpecificOperationName, itemId);

return {
data: {
type: 'addon-operation-invocations',
attributes: {
invocation_status: null,
operation_name: operationName,
operation_name: addonSpecificOperationName,
operation_kwargs: operationKwargs,
operation_result: {},
created: null,
Expand All @@ -42,14 +60,15 @@ export class AddonOperationInvocationService {
operationName: OperationNames,
itemId: string
): OperationInvocationRequestJsonApi {
const operationKwargs = this.getOperationKwargs(operationName, itemId);
const addonSpecificOperationName = this.getAddonSpecificOperationName(operationName, addon);
const operationKwargs = this.getOperationKwargs(addonSpecificOperationName, itemId);

return {
data: {
type: 'addon-operation-invocations',
attributes: {
invocation_status: null,
operation_name: operationName,
operation_name: addonSpecificOperationName,
operation_kwargs: operationKwargs,
operation_result: {},
created: null,
Expand All @@ -68,13 +87,19 @@ export class AddonOperationInvocationService {
}

private getOperationKwargs(operationName: OperationNames, itemId?: string): Record<string, unknown> {
if (!itemId || operationName === OperationNames.LIST_ROOT_ITEMS) {
const isRootOperation =
operationName === OperationNames.LIST_ROOT_ITEMS || operationName === OperationNames.LIST_ROOT_COLLECTIONS;

if (!itemId || isRootOperation) {
return {};
}

const isChildOperation =
operationName === OperationNames.LIST_CHILD_ITEMS || operationName === OperationNames.LIST_COLLECTION_ITEMS;

return {
item_id: itemId,
...(operationName === OperationNames.LIST_CHILD_ITEMS && { item_type: 'FOLDER' }),
...(isChildOperation && { item_type: 'FOLDER' }),
};
}
}
Loading