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

Add members on group create #72

Merged
merged 10 commits into from
Nov 15, 2019
Merged

Add members on group create #72

merged 10 commits into from
Nov 15, 2019

Conversation

giarc3
Copy link
Member

@giarc3 giarc3 commented Nov 8, 2019

  • Made GroupCreateOpts contain a list of UserIds that should be added as members to the group. group_create() will fail if one of these UserIds cannot be found.
  • Made group_create() return a GroupCreateApiResponse with a try_into() for a new GroupCreateResult. This result is similar to GroupMetaResult but includes a list of group admins and members.
  • Added a test for adding members on create with the members list.
  • Changed some tests to return Results and use ? instead of unwrap() to get better error messages.

TODO:

  • Changelog
  • Discuss TODO questions aimed at reviewers

@giarc3 giarc3 changed the title Added members, structs Add members on group create Nov 9, 2019
src/group.rs Outdated Show resolved Hide resolved
@@ -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> {
Copy link
Member

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.

Copy link
Member Author

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 Show resolved Hide resolved
src/group.rs Outdated Show resolved Hide resolved
src/internal/group_api/mod.rs Show resolved Hide resolved
src/group.rs Outdated Show resolved Hide resolved
src/internal/group_api/mod.rs Outdated Show resolved Hide resolved
src/internal/group_api/mod.rs Outdated Show resolved Hide resolved
src/group.rs Outdated
needs_rotation,
}
}

fn standardize(self, calling_id: &UserId) -> GroupCreateOpts {
let mut new_members = self.members.clone();
Copy link
Member

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.

Copy link
Member Author

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/mod.rs Outdated Show resolved Hide resolved
.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
Copy link
Member

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).

Copy link
Member Author

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

@giarc3 giarc3 requested a review from coltfred November 15, 2019 18:53
@giarc3 giarc3 merged commit 7ac8904 into master Nov 15, 2019
@giarc3 giarc3 deleted the 65-group-create-members branch November 15, 2019 20:01
}

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)
Copy link
Contributor

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(),
Copy link
Contributor

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...

Copy link
Member Author

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`,
Copy link
Contributor

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() {
Copy link
Contributor

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,
Copy link
Contributor

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.

clintfred added a commit that referenced this pull request Nov 20, 2019
clintfred added a commit that referenced this pull request Nov 20, 2019
clintfred added a commit that referenced this pull request Nov 20, 2019
clintfred added a commit that referenced this pull request Nov 20, 2019
clintfred added a commit that referenced this pull request Nov 20, 2019
clintfred added a commit that referenced this pull request Nov 20, 2019
clintfred added a commit that referenced this pull request Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants