Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid policy error #867

Merged
merged 2 commits into from
Jun 25, 2024
Merged

Conversation

cameronvoell
Copy link
Contributor

@cameronvoell cameronvoell commented Jun 24, 2024

Fixes #851

We were throwing an error when reading group policies whenever the policy did not exactly match the libxmtp defined policy set for our preconfigured policy set of All Members, or Admin Only. When we added a new metadata option, those preconfigured policies would add a policy for the new metadata option, and the existing group policy sets would not have that, so we would not match any of the preconfigured policy sets.

Part 1 of the fix is to make it so that if all the metadata policies match the all members / admin only policy set default, that they can still match as being All Members / Admin Only, even if they are missing or have an new metadata policy.

Part 2 of the fix is to not return an error if the group policy set does not perfectly match a preconfigured policy set, and instead return GroupPermissions::CustomPolicy. This makes the SDK more robust against updates. For example this PR updates the remove member policy to default to "admin only" for "All Members". That means existing groups who already have that policy set to "allow all" will show up in new versions as a Custom Policy instead of just erroring.

Related PRs:

@cameronvoell cameronvoell force-pushed the cv/invalid-permission-refactor-errors branch from 6705dc3 to 8d82f67 Compare June 24, 2024 23:41
@@ -994,7 +1054,7 @@ pub(crate) fn policy_all_members() -> PolicySet {
}
PolicySet::new(
MembershipPolicies::allow(),
MembershipPolicies::allow(),
MembershipPolicies::allow_if_actor_admin(),
Copy link
Contributor Author

@cameronvoell cameronvoell Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove members should require admin /super admin, even for All Member preconfigured policy to be aligned with Permissions XIP. Fixes #857

@@ -1034,12 +1094,12 @@ impl PreconfiguredPolicies {
}

pub fn from_policy_set(policy_set: &PolicySet) -> Result<Self, PolicyError> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was causing the Invalid Policy Errors on existing groups after adding group image url. The reason was that the existing policies no longer matched the "default policies" for "Add Members" or "Admin only" because those policy sets now had one new property in them.

if let Ok(preconfigured_policy) = self.inner.preconfigured_policy() {
Ok(preconfigured_policy.into())
} else {
Ok(GroupPermissions::CustomPolicy)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving forward, we wont return an error if our Policy Set does not match one of the preconfigured policies, we will just return that it is a custom policy. This policy type function is mainly used for informing users / UI

@cameronvoell cameronvoell marked this pull request as ready for review June 25, 2024 01:00
@cameronvoell cameronvoell requested a review from a team as a code owner June 25, 2024 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid Policy error
3 participants