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

Feat/add optional policies #51

Merged

Conversation

AngryDragonite
Copy link
Contributor

@AngryDragonite AngryDragonite commented Apr 27, 2024

Resolves #33

Changes proposed in this pull request:

First of all, I added migrations that create columns: optional (boolean) and additional_info (JSON) inside fof_terms_policies table. Table fof-terms-policy-user has been enriched with is_accepted (boolean) column.

Modifications inside extend.php:

  • added styles to forum
  • added controller that handles rejection of an (optional) policy,
  • added relationship fofTermsPoliciesState that allows to check which policies were accepted,
  • removed Registered event listener, its functionality is now being handled inside RegisterMiddleware.php.

Modifications inside Policy.php, UserPolicyData.php, PolicyStoreController.php, PolicyRepository.php, RegisterPolicyValidator.php:

  • generally speaking, added functionality that would integrate backend with new columns introduced in migrations,
  • validator now forces users to accept only non-optional policies.

Modifications inside RegisterMiddleware.php:

  • added functionality that handles storing the state of user's policies (wheter a policy was accepted, or not) to database.

New backend files:

  • PolicyDeclineController.php - as the name suggests. Basically, it is "1:1 copy" of PolicyAcceptController.php, however with opposite behaviour

Now lets take a look at what changed in the frontend.

Modifications inside Policy.js:

  • added optional and additional_info fields to the Policy model.

Modifications inside PolicyEdit.js:

  • added new item to fields method, which allows to choose, wheter specified Policy should be optional, or not,
  • synced initNewField method with Policy model changes,
  • modified deletePolicy method - during developing I encountered a bug - when deleting a Policy, its field is, of course deleted, but also savePolicy method is being called. It was happening possibly because when clicking Delete policy button, onsubmit method is being called.

Modifications inside AcceptPoliciesModal.js:

  • added functionality that handles rejecting an optional policy.

Modifications inside `forum/index.js':

  • instantiating new addManagePoliciesOption component.

Modifications inside admin/components/index.js:

  • exporting new ExtensionData component, so developers working on integrating fof/terms with other extensions could access this component

New frontend files:

  • ExtensionData.js - a component that allows developers to integrate fof/terms with other extensions by saving their data into fof-terms-policies table. Recipe on how to use it is descriped in README.md in For developers section.
  • addManagePoliciesOption.js - a component that allows users to opt in/out of consents in their profile settings.

Other changes:

  • admin.less & new forum.less - added some styling for components,
  • en.yml - added translations.
  • README.md - added section For developers, explaining step-by-step how to use ExtensionData component, and therefore integrate fof/terms with other extensions.

Reviewers should focus on:

I would definitely want to know, if my instructions on how to use ExtensionData in README.md are specific, exact and free of ambiguities. Every feedback on what in my code can be fixed, rewritten so it is easier to read, or is simply better is greatly welcomed :)

Screenshot

image
            admin panel - select policy as optional


image
            user settings - opt in/out of consents

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Required changes:

AngryDragonite and others added 12 commits April 19, 2024 16:07
feat: added 'is_accepted' field to fof-terms-policy-user table
feat: added settings to opt out of consents in user profile
feat: added functionality that allows users to decline policies that were declared optional
feat: added 'ExtensionData' component
…ically

feat: changed 'ExtensionData' component, so it allows other extensions to sync with fof/terms
fix: synced new model field name to its DB column
feat: started writing guide on how to integrate fof/terms with other extensions in README.md
feat: added translations
feat: improved ExtensionData component
feat: added recipe for integrating fof/terms with other extensions in README
fix: additionalInfo is now properly saved into DB
chore: removed redundant imports and comments
Copy link
Member

@DavideIadeluca DavideIadeluca left a comment

Choose a reason for hiding this comment

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

Thanks @AngryDragonite for your contribution! Just some minor things to iron out :)

migrations/2024_11_4_07_edit_terms_policies.php Outdated Show resolved Hide resolved
extend.php Outdated Show resolved Hide resolved
resources/locale/en.yml Outdated Show resolved Hide resolved
resources/locale/en.yml Outdated Show resolved Hide resolved
js/src/forum/components/addManagePoliciesOption.js Outdated Show resolved Hide resolved
AngryDragonite and others added 7 commits May 28, 2024 12:19
Co-authored-by: Davide Iadeluca <146922689+DavideIadeluca@users.noreply.github.com>
Co-authored-by: Davide Iadeluca <146922689+DavideIadeluca@users.noreply.github.com>
chore: removed accidently added files
Copy link
Member

@DavideIadeluca DavideIadeluca left a comment

Choose a reason for hiding this comment

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

Thanks @AngryDragonite for the changes. The migrations still need a look, otherwise this PR from my side is good for a merge

migrations/2024_11_4_124021_edit_terms_policies.php Outdated Show resolved Hide resolved
migrations/2024_11_4_124110_edit_terms_policy_user.php Outdated Show resolved Hide resolved
migrations/2024_23_04_124250_edit_terms_policies.php Outdated Show resolved Hide resolved
@AngryDragonite
Copy link
Contributor Author

All requested changes committed.

@DavideIadeluca DavideIadeluca requested review from imorland and removed request for dsevillamartin June 15, 2024 18:22
Copy link
Member

@imorland imorland left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @AngryDragonite and sorry it's taken us so long to look at this.

Overall I think it's okay, but I'd like to give it a spin locally before merging. Please will you remove the committed dist folder from the PR? This is not needed here as these files will be built automatically upon merge, and only cause merge conflicts at this stage.

You can do this easily: git reset HEAD js/dist and then push that change :)

@imorland
Copy link
Member

@AngryDragonite thanks for your efforts, unfortunately you're now deleting the dist folder contents, rather than simply omitting any changes to them. This should help you ;)

@rafaucau
Copy link
Contributor

@imorland There are changes to the dist folder on the master branch since this PR. Perhaps this is causing the issues?
https://github.com/FriendsOfFlarum/terms/commits/master/js/dist?since=2024-04-28&until=2024-06-16

I tried to help @AngryDragonite, but still the files are in this Pull Request.

@DavideIadeluca DavideIadeluca self-requested a review June 16, 2024 14:22
src/Middlewares/RegisterMiddleware.php Outdated Show resolved Hide resolved
src/Middlewares/RegisterMiddleware.php Outdated Show resolved Hide resolved
}
}

return $handler->handle($request);
return $response;
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason why we're not continuing down the middleware stack here?

Copy link
Contributor

@rafaucau rafaucau Jun 16, 2024

Choose a reason for hiding this comment

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

This is now handled earlier above (line 64). We need to handle this to read response body. GitHub diff is messed

$response = $handler->handle($request);

Github diff is messed in this file. Please review the entire file without viewing the diff.

migrations/2024_04_24_01_edit_terms_policies.php Outdated Show resolved Hide resolved
js/src/forum/components/addManagePoliciesOption.js Outdated Show resolved Hide resolved
@rafaucau
Copy link
Contributor

ping @imorland @DavideIadeluca

@rafaucau
Copy link
Contributor

rafaucau commented Jul 30, 2024

Maybe someone else from the FOF team could review this PR? Like, for example, @dsevillamartin
It has been waiting since April, while changes are being made to the main branch of this repo, which may cause merging conflicts.

Copy link
Member

@DavideIadeluca DavideIadeluca left a comment

Choose a reason for hiding this comment

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

Thank you for your patience. I had another look again and from my side this is good for a merge to master. Everything is working as expected locally.

About the merge conflicts, before we merge this to master I think the following should work to resolve the issue:

git fetch origin
git checkout origin/master -- js/dist/admin.js js/dist/admin.js.map js/dist/forum.js js/dist/forum.js.map
git commit -m "chore: resolve merge conflict"
git push origin feat/add-optional-policies

@rafaucau
Copy link
Contributor

@DavideIadeluca merging issue resolved

@rafaucau
Copy link
Contributor

rafaucau commented Aug 2, 2024

@DavideIadeluca So what about merge?

@DavideIadeluca
Copy link
Member

@DavideIadeluca So what about merge?

Awaiting final approval from @imorland

@AngryDragonite
Copy link
Contributor Author

ping @imorland

@AngryDragonite
Copy link
Contributor Author

@imorland @DavideIadeluca is there any chance of getting this thing done in any near future? We've been waiting for 4 months.

@imorland imorland merged commit aa2f624 into FriendsOfFlarum:master Sep 29, 2024
7 checks passed
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.

Option to withdraw acceptance of terms (optional consents).
5 participants