Skip to content

Conversation

@Paurikova2
Copy link
Collaborator

@Paurikova2 Paurikova2 commented Apr 15, 2025

Phases MP MM MB MR JM Total
ETA 0 0 0 0 0 0
Developing 1 0 0 0 0 0
Review 0 0 0 0 0 0
Total - - - - - 0
ETA est. 0
ETA cust. - - - - - 0

Problem description

When the file preview is generated via the command line, an anonymous context is used. We want to authenticate an admin user before running the script.

Summary by CodeRabbit

  • New Features
    • File preview generation now requires user authentication via email and password.
    • New command-line options allow users to provide their credentials securely.
  • Improvements
    • Enhanced help messages to document new authentication options.
    • Improved error handling for missing or invalid credentials during file preview operations.

@coderabbitai
Copy link

coderabbitai bot commented Apr 15, 2025

"""

Walkthrough

The changes introduce mandatory user authentication to the FilePreview script in DSpace. Two new command-line options, -e (email) and -p (password), are added for users to provide their credentials. The script now verifies these credentials before proceeding to generate file previews, aborting execution if authentication fails. The previous approach of running the script in an anonymous context is removed. The help documentation and command-line option parsing are updated to reflect these changes. Additionally, integration tests were enhanced to cover authentication scenarios.

Changes

File(s) Change Summary
dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java Added authentication requirement: parses -e and -p options, verifies credentials, aborts on failure, updates help text.
dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreviewConfiguration.java Added -e/--email and -p/--password options to the command-line configuration as required parameters.
dspace-api/src/test/java/org/dspace/scripts/filepreview/FilePreviewIT.java Added tests for missing email and password arguments; updated existing tests to include authentication parameters.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FilePreview Script
    participant DSpace Context
    participant EPerson (User Record)
    User->>FilePreview Script: Run script with -e (email) and -p (password)
    FilePreview Script->>DSpace Context: Initialize context
    FilePreview Script->>EPerson (User Record): Lookup by email
    alt EPerson found and password correct
        FilePreview Script->>DSpace Context: Set authenticated user
        FilePreview Script->>FilePreview Script: Generate file previews
        FilePreview Script->>DSpace Context: Commit and complete context
    else Authentication fails
        FilePreview Script->>User: Log error and abort
        FilePreview Script->>DSpace Context: Abort context
    end
Loading

Possibly related issues

Poem

A script once ran without a name,
Now asks for yours before its game.
With email and password, you step through the gate,
To preview your files—authenticated fate!
No more anonymous, the context is clear,
Secure little bunnies, your previews are here!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdecd1c and bf0b7c2.

📒 Files selected for processing (1)
  • dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Run Integration Tests
  • GitHub Check: dspace-dependencies / docker-build (linux/amd64, ubuntu-latest, true)
  • GitHub Check: Run Unit Tests

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Paurikova2 Paurikova2 self-assigned this Apr 15, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
dspace-api/src/test/java/org/dspace/scripts/filepreview/FilePreviewIT.java (4)

114-114: Fix incorrect comment.

The comment indicates that there should be no errors or warnings, but the test actually expects one error message about the missing password.

-        // There should be no errors or warnings
+        // There should be exactly one error message about missing password

103-103: Use assertion message for better failure diagnostics.

Add a descriptive message to the assertion to provide better context when the test fails.

-        assertEquals(testDSpaceRunnableHandler.getErrorMessages().size(), 1);
+        assertEquals("Should have exactly one error message", 1, testDSpaceRunnableHandler.getErrorMessages().size());

104-104: Use assertion message for better failure diagnostics.

Add a descriptive message to the assertion to provide better context when the test fails.

-        assertEquals(testDSpaceRunnableHandler.getErrorMessages().get(0), "Email is required for authentication.");
+        assertEquals("Wrong error message", "Email is required for authentication.", testDSpaceRunnableHandler.getErrorMessages().get(0));

115-116: Use assertion message for better failure diagnostics.

Add descriptive messages to the assertions to provide better context when the test fails.

-        assertEquals(testDSpaceRunnableHandler.getErrorMessages().size(), 1);
-        assertEquals(testDSpaceRunnableHandler.getErrorMessages().get(0), "Password is required for authentication.");
+        assertEquals("Should have exactly one error message", 1, testDSpaceRunnableHandler.getErrorMessages().size());
+        assertEquals("Wrong error message", "Password is required for authentication.", testDSpaceRunnableHandler.getErrorMessages().get(0));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c880d69 and 640ad2d.

📒 Files selected for processing (2)
  • dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java (7 hunks)
  • dspace-api/src/test/java/org/dspace/scripts/filepreview/FilePreviewIT.java (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: dspace-dependencies / docker-build (linux/amd64, ubuntu-latest, true)
  • GitHub Check: Run Integration Tests
  • GitHub Check: Run Unit Tests
🔇 Additional comments (5)
dspace-api/src/test/java/org/dspace/scripts/filepreview/FilePreviewIT.java (5)

95-105: Good test for verifying email requirement.

This test effectively verifies that the script requires an email for authentication, which aligns with the PR objective of removing anonymous context for file preview generation.


107-117: Good test for verifying password requirement.

This test effectively verifies that the script requires a password when an email is provided, ensuring proper authentication.


123-124: Good update to provide authentication credentials.

The test has been properly updated to include the new required authentication parameters.


141-141: Good update to provide authentication credentials.

The test has been properly updated to include the new required authentication parameters.


85-93:

Details

❌ Incorrect review comment

Consider updating testWhenNoFilesRun to include authentication.

This test doesn't include the new authentication parameters, which would likely cause it to fail with the current implementation. Consider updating it to include the email and password parameters.


🏁 Script executed:

#!/bin/bash
# Verify if the FilePreview script implementation requires authentication even when no specific operation is performed

# Check if the FilePreview class has authentication checks that would affect this test
rg -A 5 "email.*required|password.*required" dspace-api/src/main/java/org/dspace/scripts/filepreview/FilePreview.java

Length of output: 119


Final Verification Outcome: Authentication not required

Our review of the FilePreview implementation via the grep search indicates that there are no authentication checks (or email/password requirements) in the current version of FilePreview.java. Consequently, the integration test testWhenNoFilesRun is valid as-is, and updating it to include email and password parameters isn’t necessary at this time.

Likely an incorrect or invalid review comment.

@Paurikova2 Paurikova2 linked an issue Apr 15, 2025 that may be closed by this pull request
@milanmajchrak milanmajchrak changed the title UFAL/Removing anonymous context for file-preview generating by script UFAL/Run file preview as authenticated user Apr 15, 2025
@milanmajchrak milanmajchrak requested a review from vidiecan April 15, 2025 13:27
@milanmajchrak milanmajchrak merged commit ef813c1 into dtq-dev Apr 16, 2025
11 checks passed
milanmajchrak added a commit that referenced this pull request Apr 22, 2025
* Enhanced file preview feature - Run file preview as authenticated user (#936), Property to allow composing file previews (#935), Do not create temp file during generating preview (#921)

* Use the handle url instead of the items url with the UUID (#938)

* Items file metadata not correctly updated (#940)

* Remove duplicate dependency element with identical content (warnings in build)

* Anonymous users should be able to use shortener

* Fixed internal server error, when context.commit() was called multiple times in search request

* Catch DSpaceBadRequestException rather than BadRequestException

* Fixed security issue for downloading file with non anonymous license

* Fixed Clarinuserregistration nullpoint exception (#941)
kosarko added a commit to ufal/clarin-dspace that referenced this pull request May 5, 2025
pulling changes from latest (lindat-2025.04.14600125143) dataquest release

This contains the following changes:

- UFAL/Run file preview as authenticated user (dataquest-dev#936)
- Property to allow composing file previews (dataquest-dev#935)
- File preview is not loaded properly for big zip file (dataquest-dev#921)
- UFAL/Clarinuserregistration nullpoint exception (dataquest-dev#941)
- UFAL/Use the handle url instead of the items url with the UUID (dataquest-dev#938)
- UFAL/Items file metadata not correctly updated (dataquest-dev#940)
- Synchronize ufal and dataquest main branches (dataquest-dev#939)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UFAL/Remove anonymous context for file-preview generating by script

4 participants