-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add members on group create #72
Conversation
@@ -157,22 +162,35 @@ impl GroupOps for crate::IronOxide { | |||
rt.block_on(group_api::list(self.device.auth(), None)) | |||
} | |||
|
|||
fn group_create(&self, opts: &GroupCreateOpts) -> Result<GroupMetaResult> { | |||
fn group_create(&self, opts: &GroupCreateOpts) -> Result<GroupCreateResult> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't usually do any business logic up in this layer of the api so this logic should go down into group_api::group_create instead of being done up here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we talked about, I'll need some help getting the logic into the other layer
src/group.rs
Outdated
needs_rotation, | ||
} | ||
} | ||
|
||
fn standardize(self, calling_id: &UserId) -> GroupCreateOpts { | ||
let mut new_members = self.members.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to do this clone inside the if to make it not need to happen in the case where we don't have to add the calling users id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this a bit uglier but hopefully also better
src/internal/group_api/requests.rs
Outdated
.into_iter() | ||
.map(|(mem_id, (pub_key, trans_key))| GroupMember { | ||
user_id: mem_id, | ||
transform_key: trans_key.unwrap().into(), // we can unwrap because we know all members had it calculated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather match on the Some(trans_key)
and leave the None
case empty (it'll be used in the next PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to map over the option then flatten out the Nones
} | ||
|
||
impl Default for GroupCreateOpts { | ||
fn default() -> Self { | ||
// membership is the default! | ||
GroupCreateOpts::new(None, None, true, false) | ||
GroupCreateOpts::new(None, None, true, Vec::new(), false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest creating a new vec with vec![]
Applicable in some other places in this PR as well...
.into_iter() | ||
.map(|(id, user_pub_key)| { | ||
let maybe_transform_key = recrypt.generate_transform_key( | ||
&group_priv_key.clone().into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this clone needed? I don't see this being used below...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing it gives
cannot move out of `group_priv_key`, a captured variable in an `FnMut` closure
move occurs because `group_priv_key` has type `recrypt::api::PrivateKey`, which does not implement the `Copy` trait rustc(E0507)
@@ -297,47 +359,75 @@ pub(crate) fn get_group_keys<'a>( | |||
/// `user_master_pub_key` - public key of the user creating this group. | |||
/// `group_id` - unique id for the group within the segment. | |||
/// `name` - name for the group. Does not need to be unique. | |||
/// `add_as_member` - if true the user represented by the current DeviceContext will also be added to the group's membership. | |||
/// If false, the user will not be an member (but will still be an admin) | |||
/// `members` - list of user ids to add as members of the group. This list takes priority over `add_as_member`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the reference to add_as_member
in this comment as it is not part of this function's signature.
user_api::user_key_list(auth, members) | ||
.and_then(move |member_ids_and_keys| { | ||
// this will occur when one of the UserIds in the members list cannot be found | ||
if member_ids_and_keys.len() != members.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this branch should be its own function? Would this be reusable when adding admins? It certainly would be more testable on its own, IMO.
#[derive(Deserialize, Debug, Clone, PartialEq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct GroupCreateApiResponse { | ||
pub(crate) id: GroupId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been making these response objects pub(in crate:internal)
recently as we should never need these outside of the internal
portion of the crate.
GroupCreateOpts
contain a list ofUserIds
that should be added as members to the group.group_create()
will fail if one of theseUserIds
cannot be found.group_create()
return aGroupCreateApiResponse
with atry_into()
for a newGroupCreateResult
. This result is similar toGroupMetaResult
but includes a list of group admins and members.members
list.?
instead ofunwrap()
to get better error messages.TODO: