[lib] Remove membership from threads without KNOW_OF
Summary:
Right now, all rows in the roles table have the KNOW_OF permission. That guarantees that every row in the memberships table that has a role > 0 also has the KNOW_OF permission. In other words, every members of every thread has permission to see that thread.
I want to introduce a new mechanic. I want to make it so that when a user leaves or is removed from a particular kind of thread, that user is then automatically removed from some of (or all) of its descendants.
We'll want this functionality for communities that are hosted on a keyserver. If a user leaves the community, they will need to be removed for all of the threads in that community.
More immediately, we want this functionality so that when a user leaves a thread, we can automatically remove that user from all of that thread's sidebars.
In order to introduce this mechanic, I am going to make a change in a following diff that removes KNOW_OF from some rows in the roles table. I want to make it so if the user doesn't have KNOW_OF from their role or from their membership in the parent, then we remove that user as a member. I think this makes sense... if you can't know of a thread (eg. it's not synced to your client) then you're not really a member.
This diff makes it so if don't have KNOW_OF, we consider that not having any permissions, which in thread-permission-updaters.js will get treated as an operation: 'delete'.
Test Plan:
I confirmed that all rows in the production server have KNOW_OF in the following query:
sql SELECT id FROM `roles` WHERE JSON_EXTRACT(permissions, '$.know_of') IS NULL UNION SELECT thread AS id FROM `memberships` WHERE role > -1 AND JSON_EXTRACT(permissions, '$.know_of') IS NULL
I also made sure that in role-creator.js, all new roles always have KNOW_OF specified. Based on these two observations, I think I can conclude this diff shouldn't affect anything (on its own).
Reviewers: palys-swm, KatPo
Reviewed By: palys-swm, KatPo
Subscribers: zrebcu411, Adrian, atul, subnub
Differential Revision: https://phabricator.ashoat.com/D955