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

Add: Validation for Policy Upload #634

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BLasan
Copy link
Contributor

@BLasan BLasan commented Mar 25, 2024

Purpose

  • Currently, any type of file can be uploaded on a policy creation. Need to restrict the file types to .j2 and .xml
Screenshot 2024-03-25 at 18 14 06

Fixes: wso2/api-manager#2663


const handleDrop = (policyDefinition: any) => {
setPolicyDefinitionFile(policyDefinition);
if(policyDefinition===null || policyDefinition===undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting issues

Copy link
Contributor

Choose a reason for hiding this comment

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

And also this can be simplified as follows.

const handleDrop = (policyDefinition: any) => {
    if (policyDefinition && policyDefinition[0] && (policyDefinition[0].name.endsWith('.j2') || policyDefinition[0].name.endsWith('.xml'))) {
        setPolicyDefinitionFile(policyDefinition);
        return;
    }
    APIMAlert.error(intl.formatMessage({
        id: 'Uploading.Policies.Error',
        defaultMessage: 'Incompatible file type',
    }));
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@BLasan
Copy link
Contributor Author

BLasan commented Mar 26, 2024

Will add the backend validation as backend does not return an error on adding an incompatible policy file

Tharanidk pushed a commit to Tharanidk/apim-apps that referenced this pull request Mar 27, 2024
Tharanidk pushed a commit to Tharanidk/apim-apps that referenced this pull request Mar 27, 2024
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

sonarcloud bot commented Apr 18, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
6.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

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.

Add a file type restriction for operation policy definitions
3 participants