hypothesis / h

Annotate with anyone, anywhere.
https://hypothes.is/
BSD 2-Clause "Simplified" License
2.94k stars 427 forks source link

Group API `type` param 1/n: Enable setting `models.Group.type` #8910

Closed seanh closed 4 weeks ago

seanh commented 1 month ago

There is no group type column in the DB. Instead, the group table has three separate columns joinable_by, readable_by and writeable_by. models.Group.type is a @property that returns "private", "restricted" or "open" depending on the values of joinable_by, readable_by and writeable_by.

Currently models.Group.type isn't writeable: there's no setter for the property.

Add a setter for models.Group.type that accepts a simple type string "private", "restricted" or "open" and sets the underlying joinable_by, readable_by and writeable_by attributes appropriately so that reading the type property will now return the given "private", "restricted" or "open" string.

So now you can change a group's type by just doing:

some_group.type = "open"

Group type changes would normally be done via GroupUpdateService.update(). That service method just sets arbitrary kwargs on the group object so I didn't need to make any service-method changes to add support for the new type setter. Previously if you did group_update_svc.update(group, type="open") it would raise TypeError because it would try to set group.type = "open" but the property has no setter. Now it will work. I added a service test to prove this.