[ACS-9388] Print button is now disabled in viewer for media files (#4465)

* [ACS-9388] Print button is now disabled in viewer for media files

* [ACS-9388] Added canPrintFile rule to documentation. Code review fixes
This commit is contained in:
swapnil-verma-gl 2025-03-20 14:16:30 +05:30 committed by GitHub
parent ad52115f41
commit 1ef1976a4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 67 additions and 40 deletions

View File

@ -198,7 +198,7 @@ The button will be visible only when the linked rule evaluates to `true`.
## Application Evaluators ## Application Evaluators
| Ver. | Key | Description | | Ver. | Key | Description |
| ----- | ----------------------------------- | ------------------------------------------------------------------------ | |--------|-------------------------------------|---------------------------------------------------------------------------------------------------|
| 1.7.0 | app.selection.canDelete | User has permission to delete selected node(s). | | 1.7.0 | app.selection.canDelete | User has permission to delete selected node(s). |
| 1.7.0 | app.selection.canDownload | User can download selected node(s). | | 1.7.0 | app.selection.canDownload | User can download selected node(s). |
| 1.7.0 | app.selection.notEmpty | At least one node is selected. | | 1.7.0 | app.selection.notEmpty | At least one node is selected. |
@ -236,6 +236,7 @@ The button will be visible only when the linked rule evaluates to `true`.
| 1.8.0 | user.isAdmin | Checks if user is admin. | | 1.8.0 | user.isAdmin | Checks if user is admin. |
| 1.9.0 | app.canShowLogout | Whether logout action should be present or not. | | 1.9.0 | app.canShowLogout | Whether logout action should be present or not. |
| 1.12.0 | app.isLibraryManager | Checks if user is library manager. | | 1.12.0 | app.isLibraryManager | Checks if user is library manager. |
| 6.1.0 | canPrintFile | Checks if current file can be printed or not (media files such as audio/video cannot be printed). |
## Navigation Evaluators ## Navigation Evaluators

View File

@ -1070,7 +1070,8 @@
"click": "PRINT_FILE" "click": "PRINT_FILE"
}, },
"rules": { "rules": {
"visible": "canViewFile" "visible": "canViewFile",
"enabled": "canPrintFile"
} }
}, },
{ {

View File

@ -168,6 +168,7 @@ export class ContentServiceExtensionModule {
canEditFolder: rules.canEditFolder, canEditFolder: rules.canEditFolder,
isTrashcanItemSelected: rules.isTrashcanItemSelected, isTrashcanItemSelected: rules.isTrashcanItemSelected,
canViewFile: rules.canViewFile, canViewFile: rules.canViewFile,
canPrintFile: rules.canPrintFile,
canLeaveLibrary: rules.canLeaveLibrary, canLeaveLibrary: rules.canLeaveLibrary,
canToggleSharedLink: rules.canToggleSharedLink, canToggleSharedLink: rules.canToggleSharedLink,
canShowInfoDrawer: rules.canShowInfoDrawer, canShowInfoDrawer: rules.canShowInfoDrawer,

View File

@ -1360,6 +1360,18 @@ describe('app.evaluators', () => {
}); });
}); });
describe('canPrintFile', () => {
it('should return false for media files', () => {
context.selection.file = { entry: { content: { mimeType: 'video/ogg' } } } as NodeEntry;
expect(app.canPrintFile(context)).toBeFalse();
});
it('should return true for non-media files', () => {
context.selection.file = { entry: { content: { mimeType: 'application/pdf' } } } as NodeEntry;
expect(app.canPrintFile(context)).toBeTrue();
});
});
describe('canLeaveLibrary', () => { describe('canLeaveLibrary', () => {
it('should return false when no library is selected', () => { it('should return false when no library is selected', () => {
context.selection.library = null; context.selection.library = null;

View File

@ -437,6 +437,18 @@ export const isTrashcanItemSelected = (context: RuleContext): boolean => [naviga
*/ */
export const canViewFile = (context: RuleContext): boolean => [hasFileSelected(context), navigation.isNotTrashcan(context)].every(Boolean); export const canViewFile = (context: RuleContext): boolean => [hasFileSelected(context), navigation.isNotTrashcan(context)].every(Boolean);
/**
* Checks if user can print the file.
* JSON ref: `canPrintFile`
*
* @param context Rule execution context
*/
export const canPrintFile = (context: RuleContext): boolean => {
const nodeEntry = context.selection.file.entry;
const mediaMimeTypes = ['video/mp4', 'video/webm', 'video/ogg', 'audio/mpeg', 'audio/mp3', 'audio/ogg', 'audio/wav'];
return !mediaMimeTypes.includes(nodeEntry.content.mimeType);
};
/** /**
* Checks if user can **Leave** selected library. * Checks if user can **Leave** selected library.
* JSON ref: `canLeaveLibrary` * JSON ref: `canLeaveLibrary`