[server] Take parent thread permissions into account in changeRole
Summary:
I'm working on making it so that a new thread can get some of its permissions from a parent on creation and I observed a serious bug.
When calling changeRole for a thread that is being created, we have yet to commit the permissions from the thread's parent via recalculateThreadPermissions. Since we don't consider these permissions unless a row in the memberships table already exists for the given member in the new thread, we end up ignoring the permissions from the parent when determining the new thread's permissions. We do consider the new thread's permissions when calling recalculateThreadPermissions, which happens in parallel. But that result gets overriden by the result from changeRole.
changeRole has all of the data necessary to make the correct calculation, so it's okay for it to override recalculateThreadPermissions. But we need to make sure it takes permissions from the parent into account, even if those permissions haven't been set on a membership row for the child yet.
This diff basically takes the existing UNION SELECT functionality from recalculateThreadPermissions and bolts it onto changeRole.
Test Plan: Create a new sidebar in a non-PRIVATE thread (so the parent thread already has the right roles). Then try to add somebody outside the group to the sidebar (after commenting out the code on both native and server that would normally prevent this) and confirm it doesn't work
Reviewers: palys-swm
Reviewed By: palys-swm
Subscribers: KatPo, Adrian, atul
Differential Revision: https://phabricator.ashoat.com/D1025