GCTC-NTGC / gc-digital-talent

GC Digital Talent is the new recruitment platform for digital and tech jobs in the Government of Canada. // Talents numériques du GC est la nouvelle plateforme de recrutement pour les emplois numériques et technologiques au gouvernement du Canada.
https://talent.canada.ca
GNU Affero General Public License v3.0
22 stars 9 forks source link

✨ Make ExperienceSkill soft-deletable #7363

Closed tristan-orourke closed 1 year ago

tristan-orourke commented 1 year ago

✨ Feature

ExperienceSkills, the pivots between experiences and UserSkills, should be soft-deleted instead of deleted by default. Connecting a skill/userSkill to an experience should restore the appropriate soft-deleted entry, if one exists.

🕵️ Details

UserSkills already use soft-delete, and the syncSkills and connectSkills methods of Experience will restore the appropriate UserSkill if a soft-deleted row exists, before linking to it.

Now we want the ExperienceSkill entry itself to also use soft-delete. The main goal is to preserve the details field on the pivot table in the following situation:

  1. I link a skill to an experience, and write out details for it. This creates a UserSkill, and an ExperienceSkill which links to it.
  2. I delete the skill from my library, which automatically (soft-)deletes any linked ExperienceSkills (see #6942)
  3. I re-add the skill to the experience. This restores the soft-deleted UserSkill and ExperienceSkill.
  4. I see the details text I previously wrote without having to re-write it.

🙋‍♀️ Proposed Implementation

The tricky thing here is that ExperienceSkill is implemented using Laravel pivot table features, and...

Pivot models may not use the SoftDeletes trait. If you need to soft delete pivot records consider converting your pivot model to an actual Eloquent model.

So if we want to use built-in soft-delete features we'll need to convert ExperienceSkill into an actual model, and make sure it doesn't affect the API. If that's too hard, we might be able to fudge it with some clever global scopes.

Besides that, this will mostly involve code changes to the syncSkills, connectSkills and deleteSkills methods of the Experience.php class.

✅ Acceptance Criteria

A set of assumptions which, when tested, verify that the feature was properly implemented.

vd1992 commented 1 year ago

Just trying to get a feel for what is going on. So if the soft delete doesn't work, would another solution then be to: