Skip to content

Commit 8a741f8

Browse files
authored
[PM-18090] Add the Cipher Permission property to the Cipher structs. (#175)
## 🎟️ Tracking https://bitwarden.atlassian.net/browse/PM-18090 ## 📔 Objective 1. Add the `CipherPermissions` struct. 2. Add the `CipherPermissions` property to `Cipher`, `CipherView`, and `CipherListView`. 3. Update tests to account for the changes. ## Testing I talked to other team members, and we feel that the unit tests should be sufficient.
1 parent 68aac71 commit 8a741f8

File tree

8 files changed

+41
-2
lines changed

8 files changed

+41
-2
lines changed

crates/bitwarden-exporters/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl From<ImportingCipher> for CipherView {
129129
reprompt: CipherRepromptType::None,
130130
organization_use_totp: true,
131131
edit: true,
132+
permissions: None,
132133
view_password: true,
133134
local_data: None,
134135
attachments: None,

crates/bitwarden-exporters/src/models.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ mod tests {
252252
reprompt: CipherRepromptType::None,
253253
organization_use_totp: true,
254254
edit: true,
255+
permissions: None,
255256
view_password: true,
256257
local_data: None,
257258
attachments: None,
@@ -302,6 +303,7 @@ mod tests {
302303
reprompt: CipherRepromptType::None,
303304
organization_use_totp: true,
304305
edit: true,
306+
permissions: None,
305307
view_password: true,
306308
local_data: None,
307309
attachments: None,

crates/bitwarden-vault/src/cipher/attachment.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ mod tests {
242242
reprompt: CipherRepromptType::None,
243243
organization_use_totp: false,
244244
edit: true,
245+
permissions: None,
245246
view_password: true,
246247
local_data: None,
247248
attachments: None,
@@ -294,6 +295,7 @@ mod tests {
294295
reprompt: CipherRepromptType::None,
295296
organization_use_totp: false,
296297
edit: true,
298+
permissions: None,
297299
view_password: true,
298300
local_data: None,
299301
attachments: None,
@@ -350,6 +352,7 @@ mod tests {
350352
reprompt: CipherRepromptType::None,
351353
organization_use_totp: false,
352354
edit: true,
355+
permissions: None,
353356
view_password: true,
354357
local_data: None,
355358
attachments: None,

crates/bitwarden-vault/src/cipher/cipher.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use thiserror::Error;
1414
use uuid::Uuid;
1515

1616
use super::{
17-
attachment, card, field, identity,
17+
attachment, card,
18+
cipher_permissions::CipherPermissions,
19+
field, identity,
1820
local_data::{LocalData, LocalDataView},
1921
login::LoginListView,
2022
secure_note, ssh_key,
@@ -82,6 +84,7 @@ pub struct Cipher {
8284
pub reprompt: CipherRepromptType,
8385
pub organization_use_totp: bool,
8486
pub edit: bool,
87+
pub permissions: Option<CipherPermissions>,
8588
pub view_password: bool,
8689
pub local_data: Option<LocalData>,
8790

@@ -120,6 +123,7 @@ pub struct CipherView {
120123
pub reprompt: CipherRepromptType,
121124
pub organization_use_totp: bool,
122125
pub edit: bool,
126+
pub permissions: Option<CipherPermissions>,
123127
pub view_password: bool,
124128
pub local_data: Option<LocalDataView>,
125129

@@ -164,6 +168,8 @@ pub struct CipherListView {
164168
pub reprompt: CipherRepromptType,
165169
pub organization_use_totp: bool,
166170
pub edit: bool,
171+
pub permissions: Option<CipherPermissions>,
172+
167173
pub view_password: bool,
168174

169175
/// The number of attachments
@@ -234,6 +240,7 @@ impl Encryptable<KeyIds, SymmetricKeyId, Cipher> for CipherView {
234240
creation_date: cipher_view.creation_date,
235241
deleted_date: cipher_view.deleted_date,
236242
revision_date: cipher_view.revision_date,
243+
permissions: cipher_view.permissions,
237244
})
238245
}
239246
}
@@ -264,6 +271,7 @@ impl Decryptable<KeyIds, SymmetricKeyId, CipherView> for Cipher {
264271
reprompt: self.reprompt,
265272
organization_use_totp: self.organization_use_totp,
266273
edit: self.edit,
274+
permissions: self.permissions,
267275
view_password: self.view_password,
268276
local_data: self.local_data.decrypt(ctx, ciphers_key).ok().flatten(),
269277
attachments: self.attachments.decrypt(ctx, ciphers_key).ok().flatten(),
@@ -604,6 +612,7 @@ impl Decryptable<KeyIds, SymmetricKeyId, CipherListView> for Cipher {
604612
reprompt: self.reprompt,
605613
organization_use_totp: self.organization_use_totp,
606614
edit: self.edit,
615+
permissions: self.permissions,
607616
view_password: self.view_password,
608617
attachments: self
609618
.attachments
@@ -669,6 +678,8 @@ impl TryFrom<CipherDetailsResponseModel> for Cipher {
669678
.unwrap_or(CipherRepromptType::None),
670679
organization_use_totp: cipher.organization_use_totp.unwrap_or(true),
671680
edit: cipher.edit.unwrap_or(true),
681+
// TODO: add permissions when api bindings have been updated
682+
permissions: None,
672683
view_password: cipher.view_password.unwrap_or(true),
673684
local_data: None, // Not sent from server
674685
attachments: cipher
@@ -753,6 +764,7 @@ mod tests {
753764
reprompt: CipherRepromptType::None,
754765
organization_use_totp: true,
755766
edit: true,
767+
permissions: None,
756768
view_password: true,
757769
local_data: None,
758770
attachments: None,
@@ -813,6 +825,10 @@ mod tests {
813825
reprompt: CipherRepromptType::None,
814826
organization_use_totp: false,
815827
edit: true,
828+
permissions: Some(CipherPermissions {
829+
delete: false,
830+
restore: false
831+
}),
816832
view_password: true,
817833
local_data: None,
818834
attachments: None,
@@ -844,6 +860,7 @@ mod tests {
844860
reprompt: cipher.reprompt,
845861
organization_use_totp: cipher.organization_use_totp,
846862
edit: cipher.edit,
863+
permissions: cipher.permissions,
847864
view_password: cipher.view_password,
848865
attachments: 0,
849866
creation_date: cipher.creation_date,
@@ -1276,6 +1293,7 @@ mod tests {
12761293
reprompt: CipherRepromptType::None,
12771294
organization_use_totp: false,
12781295
edit: true,
1296+
permissions: None,
12791297
view_password: true,
12801298
local_data: None,
12811299
attachments: None,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use schemars::JsonSchema;
2+
use serde::{Deserialize, Serialize};
3+
4+
#[derive(Serialize, Copy, Deserialize, Debug, JsonSchema, Clone, PartialEq)]
5+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
6+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
7+
pub struct CipherPermissions {
8+
pub delete: bool,
9+
pub restore: bool,
10+
}

crates/bitwarden-vault/src/cipher/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub(crate) mod attachment;
22
pub(crate) mod card;
33
#[allow(clippy::module_inception)]
44
pub(crate) mod cipher;
5+
pub(crate) mod cipher_permissions;
56
pub(crate) mod field;
67
pub(crate) mod identity;
78
pub(crate) mod linked_id;
@@ -15,6 +16,7 @@ pub use attachment::{
1516
};
1617
pub use card::{CardBrand, CardView};
1718
pub use cipher::{Cipher, CipherError, CipherListView, CipherRepromptType, CipherType, CipherView};
19+
pub use cipher_permissions::CipherPermissions;
1820
pub use field::FieldView;
1921
pub use identity::IdentityView;
2022
pub use login::{

crates/bitwarden-vault/src/mobile/cipher_client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ mod tests {
107107
reprompt: CipherRepromptType::None,
108108
organization_use_totp: true,
109109
edit: true,
110+
permissions: None,
110111
view_password: true,
111112
local_data: None,
112113
attachments: None,
@@ -124,7 +125,7 @@ mod tests {
124125

125126
fn test_cipher() -> Cipher {
126127
Cipher {
127-
id: Some("358f2b2b-9326-4e5e-94a8-b18100bb0908".parse().unwrap()),
128+
id: Some("358f2b2b-9326-4e5e-94a8-b18100bb0908".parse().unwrap()),
128129
organization_id: None,
129130
folder_id: None,
130131
collection_ids: vec![],
@@ -149,6 +150,7 @@ mod tests {
149150
reprompt: CipherRepromptType::None,
150151
organization_use_totp: true,
151152
edit: true,
153+
permissions: None,
152154
view_password: true,
153155
local_data: None,
154156
attachments: None,

crates/bitwarden-vault/src/totp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ mod tests {
735735
reprompt: CipherRepromptType::None,
736736
organization_use_totp: true,
737737
edit: true,
738+
permissions: None,
738739
view_password: true,
739740
attachments: 0,
740741
creation_date: "2024-01-30T17:55:36.150Z".parse().unwrap(),

0 commit comments

Comments
 (0)