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

Combine UserOrGroup/PublicKey req/resp types in request layer #5

Open
clintfred opened this issue Apr 5, 2019 · 0 comments
Open

Combine UserOrGroup/PublicKey req/resp types in request layer #5

clintfred opened this issue Apr 5, 2019 · 0 comments

Comments

@clintfred
Copy link
Contributor

We have some identical or nearly identical types in the request layer that could be cleaned up and/or unified.

Note that

Examples:

In group_api/requests

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SuccessRes {
    pub(crate) user_id: UserId,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FailRes {
    pub(crate) user_id: UserId,
    pub(crate) error_message: String,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GroupUserEditResponse {
    pub(crate) succeeded_ids: Vec<SuccessRes>,
    pub(crate) failed_ids: Vec<FailRes>,
}

In document_api/requests

        #[derive(Deserialize, Debug)]
        #[serde(rename_all = "camelCase")]
        struct SuccessRes {
            pub(crate) user_or_group: UserOrGroupRes,
        }

        #[derive(Deserialize, Debug)]
        #[serde(rename_all = "camelCase")]
        struct FailRes {
            pub(crate) user_or_group: UserOrGroupRes,
            pub(crate) error_message: String,
        }

        #[derive(Deserialize, Debug)]
        #[serde(tag = "type", rename_all = "camelCase")]
        enum UserOrGroupRes {
            User { id: String },
            Group { id: String },
        }

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AccessGrant {
    pub(crate) user_or_group: UserOrGroupWithKey,
    #[serde(flatten)]
    pub(crate) encrypted_value: EncryptedOnceValue,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase", tag = "type")]
pub enum UserOrGroupWithKey {
    #[serde(rename_all = "camelCase")]
    User {
        id: String,
        // optional because the resp on document create does not return a public key
        master_public_key: Option<PublicKey>,
    },
    #[serde(rename_all = "camelCase")]
    Group {
        id: String,
        master_public_key: Option<PublicKey>,
    },
}

Notice that UserOrGroupWithKey's master_public_key is optional to support the response coming back from Document create. Document access revoke and other group apis may also be using similar types.

@clintfred clintfred changed the title Combine UserOrGroup/PublicKey req/resp types in request layer [SPIKE] Combine UserOrGroup/PublicKey req/resp types in request layer Apr 12, 2019
@ernieturner ernieturner transferred this issue from another repository May 6, 2019
@clintfred clintfred changed the title [SPIKE] Combine UserOrGroup/PublicKey req/resp types in request layer Combine UserOrGroup/PublicKey req/resp types in request layer Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants