Skip to content

Commit

Permalink
Merge pull request #2739 from BlackDex/fix-restore-revoke
Browse files Browse the repository at this point in the history
 Rename/Fix revoke/restore endpoints
  • Loading branch information
dani-garcia authored Sep 12, 2022
2 parents b050c60 + e47a2fd commit 9c891ba
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
64 changes: 56 additions & 8 deletions src/api/core/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ pub fn routes() -> Vec<Route> {
bulk_public_keys,
deactivate_organization_user,
bulk_deactivate_organization_user,
revoke_organization_user,
bulk_revoke_organization_user,
activate_organization_user,
bulk_activate_organization_user
bulk_activate_organization_user,
restore_organization_user,
bulk_restore_organization_user
]
}

Expand Down Expand Up @@ -1480,22 +1484,44 @@ async fn import(org_id: String, data: JsonUpcase<OrgImportData>, headers: Header
Ok(())
}

// Pre web-vault v2022.9.x endpoint
#[put("/organizations/<org_id>/users/<org_user_id>/deactivate")]
async fn deactivate_organization_user(
org_id: String,
org_user_id: String,
headers: AdminHeaders,
conn: DbConn,
) -> EmptyResult {
_deactivate_organization_user(&org_id, &org_user_id, &headers, &conn).await
_revoke_organization_user(&org_id, &org_user_id, &headers, &conn).await
}

// Pre web-vault v2022.9.x endpoint
#[put("/organizations/<org_id>/users/deactivate", data = "<data>")]
async fn bulk_deactivate_organization_user(
org_id: String,
data: JsonUpcase<Value>,
headers: AdminHeaders,
conn: DbConn,
) -> Json<Value> {
bulk_revoke_organization_user(org_id, data, headers, conn).await
}

#[put("/organizations/<org_id>/users/<org_user_id>/revoke")]
async fn revoke_organization_user(
org_id: String,
org_user_id: String,
headers: AdminHeaders,
conn: DbConn,
) -> EmptyResult {
_revoke_organization_user(&org_id, &org_user_id, &headers, &conn).await
}

#[put("/organizations/<org_id>/users/revoke", data = "<data>")]
async fn bulk_revoke_organization_user(
org_id: String,
data: JsonUpcase<Value>,
headers: AdminHeaders,
conn: DbConn,
) -> Json<Value> {
let data = data.into_inner().data;

Expand All @@ -1504,7 +1530,7 @@ async fn bulk_deactivate_organization_user(
Some(org_users) => {
for org_user_id in org_users {
let org_user_id = org_user_id.as_str().unwrap_or_default();
let err_msg = match _deactivate_organization_user(&org_id, org_user_id, &headers, &conn).await {
let err_msg = match _revoke_organization_user(&org_id, org_user_id, &headers, &conn).await {
Ok(_) => String::from(""),
Err(e) => format!("{:?}", e),
};
Expand All @@ -1528,7 +1554,7 @@ async fn bulk_deactivate_organization_user(
}))
}

async fn _deactivate_organization_user(
async fn _revoke_organization_user(
org_id: &str,
org_user_id: &str,
headers: &AdminHeaders,
Expand Down Expand Up @@ -1557,22 +1583,44 @@ async fn _deactivate_organization_user(
Ok(())
}

// Pre web-vault v2022.9.x endpoint
#[put("/organizations/<org_id>/users/<org_user_id>/activate")]
async fn activate_organization_user(
org_id: String,
org_user_id: String,
headers: AdminHeaders,
conn: DbConn,
) -> EmptyResult {
_activate_organization_user(&org_id, &org_user_id, &headers, &conn).await
_restore_organization_user(&org_id, &org_user_id, &headers, &conn).await
}

// Pre web-vault v2022.9.x endpoint
#[put("/organizations/<org_id>/users/activate", data = "<data>")]
async fn bulk_activate_organization_user(
org_id: String,
data: JsonUpcase<Value>,
headers: AdminHeaders,
conn: DbConn,
) -> Json<Value> {
bulk_restore_organization_user(org_id, data, headers, conn).await
}

#[put("/organizations/<org_id>/users/<org_user_id>/restore")]
async fn restore_organization_user(
org_id: String,
org_user_id: String,
headers: AdminHeaders,
conn: DbConn,
) -> EmptyResult {
_restore_organization_user(&org_id, &org_user_id, &headers, &conn).await
}

#[put("/organizations/<org_id>/users/restore", data = "<data>")]
async fn bulk_restore_organization_user(
org_id: String,
data: JsonUpcase<Value>,
headers: AdminHeaders,
conn: DbConn,
) -> Json<Value> {
let data = data.into_inner().data;

Expand All @@ -1581,7 +1629,7 @@ async fn bulk_activate_organization_user(
Some(org_users) => {
for org_user_id in org_users {
let org_user_id = org_user_id.as_str().unwrap_or_default();
let err_msg = match _activate_organization_user(&org_id, org_user_id, &headers, &conn).await {
let err_msg = match _restore_organization_user(&org_id, org_user_id, &headers, &conn).await {
Ok(_) => String::from(""),
Err(e) => format!("{:?}", e),
};
Expand All @@ -1605,7 +1653,7 @@ async fn bulk_activate_organization_user(
}))
}

async fn _activate_organization_user(
async fn _restore_organization_user(
org_id: &str,
org_user_id: &str,
headers: &AdminHeaders,
Expand Down Expand Up @@ -1634,7 +1682,7 @@ async fn _activate_organization_user(
}
}

user_org.activate();
user_org.restore();
user_org.save(conn).await?;
}
Some(_) => err!("User is already active"),
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/organization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl UserOrganization {
}
}

pub fn activate(&mut self) {
pub fn restore(&mut self) {
if self.status < UserOrgStatus::Accepted as i32 {
self.status += ACTIVATE_REVOKE_DIFF;
}
Expand Down

0 comments on commit 9c891ba

Please sign in to comment.