BSIT-3-1-APPDEV / PUPSRC-AutomatedElectionSystem

iVOTE is a web-based voting application developed for the student academic organizations of PUP Sta. Rosa Campus.
https://ivote-pupsrc.com
4 stars 8 forks source link

feat: Add phpspreadsheet library #265

Closed Andrei-Matibag closed 1 month ago

Andrei-Matibag commented 1 month ago

Overview

Documentation

PHP 7.4 or later Composer

Installation Steps

  1. Open your terminal.
  2. Navigate to your project folder.
  3. Install PHPSpreadsheet using Composer.
  4. If you get an error about missing extensions (like GD), install them:

For Windows: Enable the extension=gd and extension=zip in php.ini

Additional Information -This library is installed in the vendor folder and will be used for importing/exporting voters in the system -This library is needed as the xlsx/xls and csv files need to use the phpspreadsheet library -Activity log is also included here in this PR -This can be tested now.

This will only accept 'Student ID, Last Name', 'First Name', 'Middle Name', 'Suffix', 'Year Level', 'Section', 'Email' the COR cannot be imported within the excel/csv file as it was not possible. In excel and csv, the PDF is only imported as object and not the file itself.

The following are automatically: $role = 'student_voter'; $accountStatus = 'for_verification'; $voterStatus = 'active'; $voteStatus = NULL;

for csv/excel sample files, it can be found here: https://drive.google.com/drive/folders/1O_q27gTnlqtNn-Fk0q4zZWPpa29S1lnJ?usp=drive_link

this will close the #258 issue

C-Ivan-Bandilla commented 1 month ago

For Windows: Enable the extension in php.ini

when needed its better if you can provide the line or name

confirm if this is correct

image

Andrei-Matibag commented 1 month ago

@C-Ivan-Bandilla Yes, that's correct. I've updated the overview of this pr regarding this. Thank you.

Carl-Tabuso commented 1 month ago

UP @biellamariscotes @C-Ivan-Bandilla @Andrei-Matibag

Carl-Tabuso commented 1 month ago

@Andrei-Matibag is the import function working now? If so, can you provide a demo?

Andrei-Matibag commented 1 month ago

@Carl-Tabuso this is the demo for import that the function is working.

https://github.com/user-attachments/assets/38ae0900-96ef-4da7-9ea3-06c1b3b79caf

Carl-Tabuso commented 1 month ago

@Carl-Tabuso this is the demo for import that the function is working.

2024-07-16.20-50-30.mp4

I suggest that upon uploading an invalid file, it should be validated at that very moment. You don't wait for the user to hit the button before showing the modal.

Andrei-Matibag commented 1 month ago

@Carl-Tabuso this is the demo for import that the function is working. 2024-07-16.20-50-30.mp4

I suggest that upon uploading an invalid file, it should be validated at that very moment. You don't wait for the user to hit the button before showing the modal.

It's not an invalid file, It's an invalid format of the content inside the csv/xls file

Andrei-Matibag commented 1 month ago

I have the validation for an invalid file

Andrei-Matibag commented 1 month ago

@Carl-Tabuso this is the demo for import that the function is working. 2024-07-16.20-50-30.mp4

I suggest that upon uploading an invalid file, it should be validated at that very moment. You don't wait for the user to hit the button before showing the modal.

It's not an invalid file, It's an invalid format of the content inside the csv/xls file

I'm sorry for not showing it clearly

Carl-Tabuso commented 1 month ago

Ohh ok, I get it now. That means if the file contents are invalid, there should be a different warning modal, but in your case you simply recycled the modal for invalid file and max 25mb of size, correct?

Andrei-Matibag commented 1 month ago

Ohh ok, I get it now. That means if the file contents are invalid, there should be a different warning modal, but in your case you simply recycled the modal for invalid file and max 25mb of size, correct?

Yes. I base on Figma. So I didn't add another modal for it

Carl-Tabuso commented 1 month ago

Yes. I base on Figma. So I didn't add another modal for it

You should perhaps just change the modal title and contents in this case and have it sent to our gc.

Andrei-Matibag commented 1 month ago

Yes. I base on Figma. So I didn't add another modal for it

You should perhaps just change the modal title and contents in this case and have it sent to our gc.

Okay i'll code it and make a pr. I'll send it to our gc too

Andrei-Matibag commented 1 month ago

@Carl-Tabuso I have a question regarding the export functionality. Are we still gonna add it? In just my point of view it is repetitive because the user already imported those list of students why still export? But if we still gonna add it, in what page should we put the export functionality? There's no update in figma about this so I asked.

Carl-Tabuso commented 1 month ago

@Carl-Tabuso I have a question regarding the export functionality. Are we still gonna add it? In just my point of view it is repetitive because the user already imported those list of students why still export? But if we still gonna add it, in what page should we put the export functionality? There's no update in figma about this so I asked.

Yes, exporting files can also be used to preserve and copy old accounts in the event of permanent deletion or data migration.

About the export UI, I'll ask Yuri and others to provide an update.

Andrei-Matibag commented 1 month ago

@Carl-Tabuso I have a question regarding the export functionality. Are we still gonna add it? In just my point of view it is repetitive because the user already imported those list of students why still export? But if we still gonna add it, in what page should we put the export functionality? There's no update in figma about this so I asked.

Yes, exporting files can also be used to preserve and copy old accounts in the event of permanent deletion or data migration.

About the export UI, I'll ask Yuri and others to provide an update.

Thank you @Carl-Tabuso

gitguardian[bot] commented 1 month ago

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | | | -------------- | ------------------ | ------------------------------ | ---------------- | --------------- | -------------------- | | [13043212](https://dashboard.gitguardian.com/workspace/558516/incidents/13043212?occurrence=160730081) | Triggered | SMTP credentials | b1542b293bc67ffd4c3bd97ca5910b27b5c3b296 | src/includes/mailer-test.php | [View secret](https://github.com/BSIT-3-1-APPDEV/PUPSRC-AutomatedElectionSystem/commit/b1542b293bc67ffd4c3bd97ca5910b27b5c3b296#diff-7c014e330afeb8f6740ef0b23948f90e2f4ac56301328b1991f074c8c3118f83R36) |
🛠 Guidelines to remediate hardcoded secrets
1. Understand the implications of revoking this secret by investigating where it is used in your code. 2. Replace and store your secret safely. [Learn here](https://blog.gitguardian.com/secrets-api-management?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) the best practices. 3. Revoke and [rotate this secret](https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/specifics/smtp_assignment#revoke-the-secret?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). 4. If possible, [rewrite git history](https://blog.gitguardian.com/rewriting-git-history-cheatsheet?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment). Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data. To avoid such incidents in the future consider - following these [best practices](https://blog.gitguardian.com/secrets-api-management/?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) for managing and storing secrets including API keys and other credentials - install [secret detection on pre-commit](https://docs.gitguardian.com/ggshield-docs/integrations/git-hooks/pre-commit?utm_source=product&utm_medium=GitHub_checks&utm_campaign=check_run_comment) to catch secret before it leaves your machine and ease remediation.

🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Carl-Tabuso commented 1 month ago

Is the arrangement of columns here is what will be followed across all orgs — have you talked abut this matter with biella? If so, we may proceed with the merging of this pr

Carl-Tabuso commented 1 month ago

I have an issue with the file input field allowing attachments of pdf. You should add a client-side validation for this. We don't wait for the user to click the button, for him to realize he uploaded a wrong file extension. Kind of like how it works in the registration page. Upon import, the file size and extension is validated on the client-side but also on the server-side later. It bothers me that there is a page reload after clicking the import voters or close button. You can implement ajax for this.

https://github.com/user-attachments/assets/cb8f6dec-4d7a-47c3-a4f9-cd8821d4b6c7

Carl-Tabuso commented 1 month ago

It's quite unclear also to say that there's a duplicate of users found if those user accounts are in the recycle bin. What you can do is rephrase the modal. You can still say that there's a duplicate found and they may also check the recycle bin for such duplicates. You should also add a button state if the server-side is processing the data from the imported file. From the video below, the Import Voters button is vulnerable to shotgun clicks. And yes, the page reload is uncalled for.

Take a closer look here:

https://github.com/user-attachments/assets/5f07ccd0-9290-4390-a5dd-a83c3c8db340

Andrei-Matibag commented 1 month ago

Is the arrangement of columns here is what will be followed across all orgs — have you talked abut this matter with biella? If so, we may proceed with the merging of this pr

We talked about it. She sends the format but we will follow the format I sent. I will just insert the Student ID column as the first header

Andrei-Matibag commented 1 month ago

It's quite unclear also to say that there's a duplicate of users found if those user accounts are in the recycle bin. What you can do is rephrase the modal. You can still say that there's a duplicate found and they may also check the recycle bin for such duplicates. You should also add a button state if the server-side is processing the data from the imported file. From the video below, the Import Voters button is vulnerable to shotgun clicks. And yes, the page reload is uncalled for.

Take a closer look here:

2024-07-17.13-50-04.mp4

I managed to fix this. It will reject the import process even if there's a single invalid data or format in the excel file. It will not be vulnerable to shotgun clicks because it will keep showing the invalid modal.

Andrei-Matibag commented 1 month ago

I will update my pr and the format in the google drive

Andrei-Matibag commented 1 month ago

I included the Student ID but it will not saved in the DB. I disable the button while importing.

https://github.com/user-attachments/assets/08ca82c2-68d1-4723-beb0-e3599ec2b57c

Andrei-Matibag commented 1 month ago

I updated the sample formats in the google drive

C-Ivan-Bandilla commented 1 month ago

Does it check the file for duplicates entries? image image

Sample-Voters.csv

https://drive.google.com/file/d/1t42Kqb5xGiMn6pqdFVYss4GqExUSRjCJ/view?usp=sharing

Andrei-Matibag commented 1 month ago

Does it check the file for duplicates entries? image image

Sample-Voters.csv

https://drive.google.com/file/d/1t42Kqb5xGiMn6pqdFVYss4GqExUSRjCJ/view?usp=sharing

does it have same student ID?

C-Ivan-Bandilla commented 1 month ago

does it have same student ID?

Yes it has image image

This may be user fault but may cause issues in the system if not handled especially if the number of imported users are numerous such as resetting password by email may fail and etc.

Andrei-Matibag commented 1 month ago

I have an issue with the file input field allowing attachments of pdf. You should add a client-side validation for this. We don't wait for the user to click the button, for him to realize he uploaded a wrong file extension. Kind of like how it works in the registration page. Upon import, the file size and extension is validated on the client-side but also on the server-side later. It bothers me that there is a page reload after clicking the import voters or close button. You can implement ajax for this.

2024-07-17.13-42-34.mp4

I managed to fix this. I disabled the button when putting a file other than csv/xls file. I also include the modal of invalid file format

Andrei-Matibag commented 1 month ago

does it have same student ID?

Yes it has image image

This may be user fault but may cause issues in the system if not handled especially if the number of imported users are numerous such as resetting password by email may fail and etc.

I fixed this. I put a validation to check duplication of the prefix of email and the "00000" part of the student ID within the file and database for the email

Andrei-Matibag commented 1 month ago

does it have same student ID?

Yes it has image image This may be user fault but may cause issues in the system if not handled especially if the number of imported users are numerous such as resetting password by email may fail and etc.

I fixed this. I put a validation to check duplication of the prefix of email and the "00000" part of the student ID within the file and database for the email

If there's a problem in the Student ID part. I'll try to fix it as soon as possible

C-Ivan-Bandilla commented 1 month ago

If there's a problem in the Student ID part. I'll try to fix it as soon as possible

Will check right now

github-actions[bot] commented 1 month ago

:tada: This PR is included in version 2.39.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Carl-Tabuso commented 1 month ago

Does this not need an issue ticket label?