Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file upload max size feature #328

Merged
merged 3 commits into from
Mar 12, 2024
Merged

Conversation

madassdev
Copy link
Collaborator

@madassdev madassdev commented Feb 28, 2024

Summary by CodeRabbit

  • New Features
    • Enhanced file upload fields with dynamic calculation for maximum file size to improve user experience.
    • Added validation rule for maximum file size, preventing users from uploading oversized files.
    • Improved UI in form fields to display and validate maximum file size in megabytes (MB).

@madassdev madassdev requested a review from JhumanJ February 28, 2024 12:43
Copy link
Contributor

coderabbitai bot commented Feb 28, 2024

Walkthrough

The updates aim to enhance file size validation throughout the application. A new method for dynamically determining maximum file sizes has been introduced, alongside validation rules to enforce these limits. These changes cover both server-side and client-side components, ensuring consistent application of file size restrictions based on various settings like field properties, form configurations, and workspace constraints. This comprehensive approach improves user experience and system robustness by preventing oversized file uploads.

Changes

File Path Change Summary
app/Http/Requests/.../AnswerFormRequest.php Added dynamic file size calculation method; updated getPropertyRules usage for dynamic size calculation.
app/Http/Requests/.../UserFormRequest.php Introduced max_file_size validation rule under properties.* for file size validation.
client/components/open/forms/OpenFormField.vue Modified mbLimit calculation to dynamically adjust file size limits based on field, form, or workspace settings.
client/components/open/forms/fields/components/FieldOptions.vue Added max_file_size input for specifying file size and computed mbLimit to derive max file size from form or workspace settings.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8a06701 and 89d23fd.
Files selected for processing (4)
  • app/Http/Requests/AnswerFormRequest.php (2 hunks)
  • app/Http/Requests/UserFormRequest.php (1 hunks)
  • client/components/open/forms/OpenFormField.vue (1 hunks)
  • client/components/open/forms/fields/components/FieldOptions.vue (4 hunks)
Additional comments: 4
app/Http/Requests/AnswerFormRequest.php (2)
  • 30-34: The implementation of the getFieldMaxFileSize method is sound and aligns well with the PR's objectives of dynamically calculating file size limits. It correctly calculates the maximum file size by considering both the field-specific limit and the workspace limit, ensuring flexibility and consistency in file size validation.
  • 189-189: The updated usage of getFieldMaxFileSize in getPropertyRules for file validation is correctly implemented. It ensures that the file size validation dynamically considers both the field-specific and workspace limits, enhancing the robustness of file upload handling.
client/components/open/forms/OpenFormField.vue (1)
  • 306-306: The modification to the calculation of the mbLimit property is well-implemented and aligns with the PR's objectives of dynamically managing file size limits. The use of conditional expressions and logical operators ensures that the most restrictive file size limit is applied, enhancing the application's usability and preventing user confusion.
client/components/open/forms/fields/components/FieldOptions.vue (1)
  • 455-457: The mbLimit computed property effectively uses a fallback mechanism to determine the maximum file size, prioritizing the form's max_file_size over the workspace's. This is a solid approach for flexibility and ensuring that the most specific limit is applied. However, it's important to ensure that both form.max_file_size and currentWorkspace.max_file_size are always defined and validated on the backend to prevent any unexpected behavior.

Comment on lines 64 to 69
<text-input name="max_file_size" class="mt-3" :form="field" native-type="number"
:min="1"
:max="mbLimit"
label="Maximum file size" :placeholder="`1MB - ${mbLimit}MB`"
help="Set the maximum file size that can be uploaded in MB."
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

The addition of the max_file_size text input field with dynamic minimum and maximum values is a good implementation for allowing users to specify file size limits. However, consider adding client-side validation to ensure that the input is a positive integer and within a reasonable range to prevent potential issues with extremely high values that could affect the system's performance or usability.

+ <v-text-field type="number" v-model.number="field.max_file_size" :min="1" :max="mbLimit" integer-only />

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
<text-input name="max_file_size" class="mt-3" :form="field" native-type="number"
:min="1"
:max="mbLimit"
label="Maximum file size" :placeholder="`1MB - ${mbLimit}MB`"
help="Set the maximum file size that can be uploaded in MB."
/>
<text-input name="max_file_size" class="mt-3" :form="field" native-type="number"
:min="1"
:max="mbLimit"
label="Maximum file size" :placeholder="`1MB - ${mbLimit}MB`"
help="Set the maximum file size that can be uploaded in MB."
/>
<v-text-field type="number" v-model.number="field.max_file_size" :min="1" :max="mbLimit" integer-only />

@@ -118,6 +118,9 @@ public function rules()
'properties.*.generates_uuid' => 'boolean|nullable',
'properties.*.generates_auto_increment_id' => 'boolean|nullable',

// For file (min and max)
'properties.*.max_file_size' => 'min:1|numeric',
Copy link
Contributor

Choose a reason for hiding this comment

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

The validation rule for max_file_size correctly ensures that the value is numeric and at least 1. However, to prevent potential abuse or unintentional configuration errors, it might be beneficial to also enforce an upper limit. Consider modifying the validation rule to include a reasonable maximum value, such as numeric|min:1|max:100 (assuming the maximum file size is 100MB as an example). This ensures that file sizes are within a reasonable range.

- 'properties.*.max_file_size' => 'min:1|numeric',
+ 'properties.*.max_file_size' => 'numeric|min:1|max:100', // Adjust the max value as appropriate

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
'properties.*.max_file_size' => 'min:1|numeric',
'properties.*.max_file_size' => 'numeric|min:1|max:100', // Adjust the max value as appropriate

Copy link
Owner

@JhumanJ JhumanJ left a comment

Choose a reason for hiding this comment

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

Great, thanks!

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 89d23fd and a8a0327.
Files selected for processing (1)
  • client/components/open/forms/fields/components/FieldOptions.vue (4 hunks)
Additional comments: 3
client/components/open/forms/fields/components/FieldOptions.vue (3)
  • 64-69: The addition of the <text-input> component for setting the maximum file size is well-implemented. It uses the mbLimit computed property to dynamically set the range of acceptable file sizes, enhancing the flexibility of file upload constraints. This change aligns with the PR objectives to provide dynamic feedback on file size limits.
  • 438-439: The setup() function correctly retrieves the currentWorkspace using a computed property. This approach is efficient for accessing reactive state within the Vue Composition API, ensuring that the component can dynamically adjust to changes in the workspace settings.
  • 455-457: The mbLimit computed property effectively determines the maximum file size based on form and workspace settings. This dynamic calculation supports the PR's goal of flexible file upload constraints. It's a good practice to use computed properties for reactive data that depends on other reactive sources.

Comment on lines +520 to +522
if (this.field.type == 'files') {
this.field.max_file_size = Math.min((this.field.max_file_size ?? this.mbLimit), this.mbLimit)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic to set max_file_size for file type fields based on the minimum of form and workspace limits is a crucial update. It ensures that the file size limit is consistently enforced across different levels of settings. However, as previously commented, consider adding a user notification or confirmation step if the max_file_size is adjusted to a lower value than a previously set one. This would enhance user awareness and control over the changes.

+ if (this.field.max_file_size > this.mbLimit) {
+   // Notify the user that the max_file_size has been adjusted to the mbLimit
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (this.field.type == 'files') {
this.field.max_file_size = Math.min((this.field.max_file_size ?? this.mbLimit), this.mbLimit)
}
if (this.field.type == 'files') {
this.field.max_file_size = Math.min((this.field.max_file_size ?? this.mbLimit), this.mbLimit)
if (this.field.max_file_size > this.mbLimit) {
// Notify the user that the max_file_size has been adjusted to the mbLimit
}
}

Copy link
Owner

@JhumanJ JhumanJ left a comment

Choose a reason for hiding this comment

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

Great work thanks!

@JhumanJ JhumanJ merged commit 7b89ebd into main Mar 12, 2024
5 checks passed
@JhumanJ JhumanJ deleted the 7fd29-customizable-file-upload-size-limit branch March 12, 2024 17:27
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.

2 participants