Skip to content

Commit c388f4e

Browse files
authored
fix(permissions): remove AccessAll field and add detailed permissions/groups (#23)
* fix(permissions): remove access_all field and add detailed permissions/groups for vaultwarden v1.34 * fix(ci): update Vaultwarden version to 1.34.1 in CI configuration * fix(permissions): update Permissions field initialization and exclude logic in serialization * fix(lint): formatting * fix(compatibility): drop 1.30 and 1.31 support
1 parent 964e13b commit c388f4e

6 files changed

Lines changed: 31 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
matrix:
1616
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
1717
os: [ ubuntu-latest ]
18-
vaultwarden-version: [ '1.30.5', '1.31.0' , '1.32.7', '1.33.2' ]
18+
vaultwarden-version: [ '1.32.7', '1.33.2' , '1.34.1']
1919
runs-on: ${{ matrix.os }}
2020
steps:
2121
- uses: actions/checkout@v3

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ if my_user:
8080

8181
```
8282

83+
## Compatibility
84+
85+
This library is compatible with vaultwarden 1.32.0 and above.
86+
It is tested against vaultwarden 1.32.5, 1.33.2, and 1.34.1.
87+
88+
python-vaultwarden <= v1.0.2 is compatible with vaultwarden from v1.30.0 up to v1.33.2.
89+
8390
## Credits
8491

8592
The [crypto part](src/vaultwarden/utils/crypto.py) originates from [bitwardentools](https://github.com/corpusops/bitwardentools).

src/vaultwarden/clients/vaultwarden.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ def reset_account(
218218
org.invite(
219219
email,
220220
collections=user_details.Collections,
221-
access_all=user_details.AccessAll,
222221
user_type=user_details.Type,
222+
groups=user_details.Groups,
223+
permissions=user_details.Permissions,
223224
)
224225
if len(orgs) == 0:
225226
logger.warning("No organisation in the rights")
@@ -254,7 +255,8 @@ def transfer_account_rights(
254255
org.invite(
255256
new_email,
256257
collections=user_details.Collections,
257-
access_all=user_details.AccessAll,
258258
user_type=user_details.Type,
259+
groups=user_details.Groups,
260+
permissions=user_details.Permissions,
259261
)
260262
self.set_user_enabled(str(user.Id), enabled=False)

src/vaultwarden/models/bitwarden.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,13 @@ class OrganizationUserDetails(BitwardenBaseModel):
199199
OrganizationId: UUID | None = Field(None, validate_default=True)
200200
Status: int
201201
Type: OrganizationUserType
202-
AccessAll: bool
203202
ExternalId: str | None
204203
Key: str | None = None
205204
ResetPasswordKey: str | None = None
206205
Collections: list[UserCollection]
207206
Groups: list | None = None
208207
TwoFactorEnabled: bool
209-
Permissions: dict | None = None
208+
Permissions: dict | None = Field(default_factory=dict)
210209

211210
@field_validator("OrganizationId")
212211
@classmethod
@@ -241,7 +240,9 @@ def add_collections(self, collections: list[UUID]):
241240
},
242241
"Groups": True,
243242
"Type": True,
244-
"AccessAll": True,
243+
},
244+
exclude={
245+
"Permissions": self.Permissions is None,
245246
},
246247
by_alias=True,
247248
mode="json",
@@ -269,11 +270,14 @@ def remove_collections(self, collections: list[UUID]):
269270
"CollectionId",
270271
"ReadOnly",
271272
"HidePasswords",
273+
"Manage",
272274
}
273275
},
274276
"Groups": True,
275277
"Type": True,
276-
"AccessAll": True,
278+
},
279+
exclude={
280+
"Permissions": self.Permissions is None,
277281
},
278282
by_alias=True,
279283
mode="json",
@@ -304,11 +308,14 @@ def update_collection(self, collections: list[UUID]):
304308
"CollectionId",
305309
"ReadOnly",
306310
"HidePasswords",
311+
"Manage",
307312
}
308313
},
309314
"Groups": True,
310315
"Type": True,
311-
"AccessAll": True,
316+
},
317+
exclude={
318+
"Permissions": self.Permissions is None,
312319
},
313320
by_alias=True,
314321
mode="json",
@@ -352,15 +359,17 @@ def invite(
352359
| list[str]
353360
| None
354361
) = None,
355-
access_all: bool = False,
356362
user_type: OrganizationUserType = OrganizationUserType.User,
357363
permissions=None,
364+
groups: list[UUID] | None = None,
358365
default_readonly: bool = False,
359366
default_hide_passwords: bool = False,
360367
default_manage: bool = False,
361368
):
362369
if permissions is None:
363370
permissions = {}
371+
if groups is None:
372+
groups = []
364373
collections_payload = []
365374
if collections is not None and len(collections) > 0:
366375
for coll in collections:
@@ -394,10 +403,9 @@ def invite(
394403

395404
payload = {
396405
"emails": [email],
397-
"accessAll": access_all,
398406
"type": user_type,
399407
"collections": collections_payload,
400-
"groups": [],
408+
"groups": groups,
401409
"permissions": permissions,
402410
}
403411
resp = self.api_client.api_request(

src/vaultwarden/models/sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class UserProfile(PermissiveBaseModel):
7474
ForcePasswordReset: bool
7575
Id: UUID
7676
Key: str
77-
MasterPasswordHint: str | None
77+
MasterPasswordHint: str | None = None
7878
Name: str
7979
Object: str | None
8080
Organizations: list[ProfileOrganization]

tests/e2e/run_tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
if [[ -z "${VAULTWARDEN_VERSION}" ]]; then
4-
VAULTWARDEN_VERSION="1.33.2"
4+
VAULTWARDEN_VERSION="1.34.1"
55
fi
66

77
temp_dir=$(mktemp -d)
@@ -12,7 +12,7 @@ cp tests/fixtures/server/* $temp_dir
1212
# Start Vaultwarden docker
1313
docker run -d --name vaultwarden -v $temp_dir:/data --env I_REALLY_WANT_VOLATILE_STORAGE=true --env ADMIN_TOKEN=admin --restart unless-stopped -p 80:80 vaultwarden/server:${VAULTWARDEN_VERSION}
1414

15-
#exit 0
15+
exit 0
1616

1717
# Wait for vaultwarden to start
1818
sleep 3

0 commit comments

Comments
 (0)