City-of-Helsinki/harrastuspassi-backend

As a service provider I can manage my Hobbies

Opened this issue · 1 comments

Users representing a service provider must be able to create and manage hobbies provided by that service provider.

Municipality moderators must be able to moderate the hobbies that are being provided within their municipality, so the municipality information must be included in the hobbies created by the service provider users.

Note that in the Hobby model there is also an organizer field, but for the purpose of this issue it should not be mixed with the concept of a service provider.

Suggestion for the implementation

  • A new model ServiceProvider will be added.
  • ServiceProvider will have a default_municipality field. This will be used to determine the municipality of the Hobby objects created by the ServiceProvider. This way changes to the admin UI are not needed in this issue. Later if ServiceProviders operate in multiple municipalities, a municipality field can be added to the admin UI, where the default value is picked from default_municipality.
  • ServiceProvider will have a many-to-many field pointing to the User model. These are the users who represent the service provider, and have access to create and manage the service provider's hobbies.
  • In tasks.py permission update tasks, a check through the ServiceProvider users many-to-many will be added, similar to municipality.moderators.
  • perform_create for Hobby, Location and Promotion will be changed to get the municipality through ServiceProvider.default_municipality. Additional logic can be added to see if the old municipality moderator relation should be used, or the new service provider relation.

Because Municipality objects have been used to emulate ServiceProvider in the absence of the concept of a service provider this data needs to be migrated.

  • A data migration will be created, in the form of a script or management command, not through the Django migration files.
  • The data migration will
    • Copy data from Municipality objects into ServiceProvider objects
    • Point all Hobby objects to the ServiceProvider object corresponding the old Municipality object.
    • Add all Users from Municipality.moderators into the ServiceProvider User many-to-many.
    • Set the ServiceProvider.default_municipality to the correct municipality, such as Helsinki.