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 action to promote a user to an admin #59

Merged
merged 36 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0945bc2
Interact with peer data via Secret Storage module
amandahla Oct 3, 2023
a7e5128
Merge branch 'main' into ISD-1112-synapse-add-action-to-make-user-an-…
amandahla Oct 4, 2023
7969b98
Merge remote-tracking branch 'origin' into ISD-1112-synapse-add-actio…
amandahla Oct 4, 2023
6f0b8d8
Fix typo
amandahla Oct 4, 2023
ee8bc39
Add change-user-admin action
amandahla Oct 4, 2023
d8e32ff
Replace Change for Promote
amandahla Oct 9, 2023
2c9a20a
Change server from optional to str
amandahla Oct 9, 2023
e3ddd99
Remove PebbleServiceError exception
amandahla Oct 9, 2023
d06f34f
Remove BlockedStatus from action
amandahla Oct 9, 2023
49c916a
Expand docstring about peer data
amandahla Oct 9, 2023
527932a
Add AdminAccessTokenNotFoundError exception
amandahla Oct 10, 2023
bfc6be4
Remove _admin_access_token property
amandahla Oct 10, 2023
f2e303b
Add JUJU_HAS_SECRETS constant
amandahla Oct 10, 2023
a8a767e
Use private method to generate authorization header
amandahla Oct 10, 2023
06bf65f
Fix method and add integration test
amandahla Oct 10, 2023
4a77992
Add unit tests
amandahla Oct 10, 2023
cc08310
Make admin_access_token str instead of Optional
amandahla Oct 11, 2023
a3b52b2
Minor fixes
amandahla Oct 11, 2023
6663cdd
Delete promote_user_admin.py
amandahla Oct 11, 2023
f5e2cdc
Merge branch 'main' into ISD-1112-synapse-add-action-to-make-user-an-…
amandahla Oct 16, 2023
6485564
Fix union-attr error
amandahla Oct 16, 2023
66fbdc5
Add test_enable_saml_success_no_ubuntu_url unit test
amandahla Oct 16, 2023
a92271a
Change import to src-docs work and fix src-docs by removing directory…
amandahla Oct 16, 2023
555b71f
Add get_admin_access_token to the charm so interaction with Secret an…
amandahla Oct 16, 2023
a61bf4d
Fix/remove existing unit tests
amandahla Oct 16, 2023
2dbe265
Add unit tests
amandahla Oct 17, 2023
1591fff
Check for SecretNotFoundError
amandahla Oct 17, 2023
0626ab6
Add more unit tests to make coverage happy
amandahla Oct 17, 2023
7d6daae
Merge branch 'main' into ISD-1112-synapse-add-action-to-make-user-an-…
amandahla Oct 17, 2023
25cad40
Merge branch 'main' into ISD-1112-synapse-add-action-to-make-user-an-…
amandahla Oct 18, 2023
4cfcc1b
Merge branch 'main' into ISD-1112-synapse-add-action-to-make-user-an-…
amandahla Oct 18, 2023
74e113c
Merge branch 'main' into ISD-1112-synapse-add-action-to-make-user-an-…
amandahla Oct 18, 2023
ecc37dd
Merge branch 'main' into ISD-1112-synapse-add-action-to-make-user-an-…
amandahla Oct 19, 2023
8dc2388
Merge branch 'main' into ISD-1112-synapse-add-action-to-make-user-an-…
amandahla Oct 20, 2023
140cc36
Fix log and add test
amandahla Oct 20, 2023
6d99b5c
Merge branch 'main' into ISD-1112-synapse-add-action-to-make-user-an-…
amandahla Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ register-user:
default: false
required:
- username
change-user-admin:
description: |
Change whether a user is a server administrator.
amandahla marked this conversation as resolved.
Show resolved Hide resolved
You need to supply a user name.
properties:
username:
description: |
User name to be changed to admin.
amandahla marked this conversation as resolved.
Show resolved Hide resolved
type: string
102 changes: 68 additions & 34 deletions src-docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Helper module used to manage interactions with Synapse API.
- **SYNAPSE_PORT**
- **SYNAPSE_URL**
- **ADD_USER_ROOM_URL**
- **CHANGE_USER_ADMIN_URL**
- **CREATE_ROOM_URL**
- **DEACTIVATE_ACCOUNT_URL**
- **LIST_ROOMS_URL**
Expand All @@ -23,7 +24,7 @@ Helper module used to manage interactions with Synapse API.

---

<a href="../src/synapse/api.py#L96"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L98"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `register_user`

Expand Down Expand Up @@ -61,7 +62,7 @@ Register user.

---

<a href="../src/synapse/api.py#L213"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L215"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `get_version`

Expand Down Expand Up @@ -90,12 +91,16 @@ We're using retry here because after the config change, Synapse is restarted.

---

<a href="../src/synapse/api.py#L245"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L247"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `get_access_token`

```python
get_access_token(user: User, server: str, admin_access_token: str) → str
get_access_token(
user: User,
server: str,
admin_access_token: Optional[str]
) → str
```

Get an access token that can be used to authenticate as that user.
Expand Down Expand Up @@ -124,14 +129,14 @@ This is a way to do actions on behalf of a user.

---

<a href="../src/synapse/api.py#L274"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L276"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `override_rate_limit`

```python
override_rate_limit(
user: User,
admin_access_token: str,
admin_access_token: Optional[str],
amandahla marked this conversation as resolved.
Show resolved Hide resolved
charm_state: CharmState
) → None
```
Expand All @@ -149,12 +154,12 @@ Override user's rate limit.

---

<a href="../src/synapse/api.py#L292"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L296"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `get_room_id`

```python
get_room_id(room_name: str, admin_access_token: str) → Optional[str]
get_room_id(room_name: str, admin_access_token: Optional[str]) → Optional[str]
```

Get room id.
Expand All @@ -180,12 +185,16 @@ Get room id.

---

<a href="../src/synapse/api.py#L328"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L332"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `deactivate_user`

```python
deactivate_user(user: User, server: str, admin_access_token: str) → None
deactivate_user(
user: User,
server: str,
admin_access_token: Optional[str]
) → None
```

Deactivate user.
Expand All @@ -201,12 +210,12 @@ Deactivate user.

---

<a href="../src/synapse/api.py#L350"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L354"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `create_management_room`

```python
create_management_room(admin_access_token: str) → str
create_management_room(admin_access_token: Optional[str]) → str
```

Create the management room to be used by Mjolnir.
Expand All @@ -231,15 +240,15 @@ Create the management room to be used by Mjolnir.

---

<a href="../src/synapse/api.py#L404"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L408"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `make_room_admin`

```python
make_room_admin(
user: User,
server: str,
admin_access_token: str,
admin_access_token: Optional[str],
room_id: str
) → None
```
Expand All @@ -258,14 +267,39 @@ Make user a room's admin.

---

<a href="../src/synapse/api.py#L43"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L472"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `change_user_admin`

```python
change_user_admin(
user: User,
server: Optional[str],
admin_access_token: Optional[str]
) → None
```

Change user to admin.



**Args:**

- <b>`user`</b>: user to be changed to admin.
- <b>`server`</b>: to be used to create the user id.
- <b>`admin_access_token`</b>: server admin access token to be used.


---

<a href="../src/synapse/api.py#L45"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `APIError`
Exception raised when something fails while calling the API.

Attrs: msg (str): Explanation of the error.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -287,12 +321,12 @@ Initialize a new instance of the APIError exception.

---

<a href="../src/synapse/api.py#L59"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L61"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `NetworkError`
Exception raised when requesting API fails due network issues.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -314,12 +348,12 @@ Initialize a new instance of the APIError exception.

---

<a href="../src/synapse/api.py#L63"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L65"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `GetNonceError`
Exception raised when getting nonce fails.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -341,12 +375,12 @@ Initialize a new instance of the APIError exception.

---

<a href="../src/synapse/api.py#L67"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L69"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `GetVersionError`
Exception raised when getting version fails.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -368,12 +402,12 @@ Initialize a new instance of the APIError exception.

---

<a href="../src/synapse/api.py#L71"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L73"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `VersionUnexpectedContentError`
Exception raised when output of getting version is unexpected.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -395,12 +429,12 @@ Initialize a new instance of the APIError exception.

---

<a href="../src/synapse/api.py#L75"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L77"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `GetRoomIDError`
Exception raised when getting room id fails.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -422,12 +456,12 @@ Initialize a new instance of the APIError exception.

---

<a href="../src/synapse/api.py#L79"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L81"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `GetUserIDError`
Exception raised when getting user id fails.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -449,12 +483,12 @@ Initialize a new instance of the APIError exception.

---

<a href="../src/synapse/api.py#L83"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L85"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `UserExistsError`
Exception raised when checking if user exists fails.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -476,12 +510,12 @@ Initialize a new instance of the APIError exception.

---

<a href="../src/synapse/api.py#L87"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L89"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `GetAccessTokenError`
Exception raised when getting access token fails.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -503,12 +537,12 @@ Initialize a new instance of the APIError exception.

---

<a href="../src/synapse/api.py#L91"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L93"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `RegisterUserError`
Exception raised when registering user fails.

<a href="../src/synapse/api.py#L50"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/synapse/api.py#L52"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand Down
68 changes: 68 additions & 0 deletions src-docs/change_user_admin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!-- markdownlint-disable -->

<a href="../src/actions/change_user_admin.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

# <kbd>module</kbd> `change_user_admin`
Module to interact with Change User Admin action.


---

<a href="../src/actions/change_user_admin.py#L34"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `change_user_admin`

```python
change_user_admin(
username: str,
server: Optional[str],
admin_access_token: Optional[str]
) → None
```

Run register user action.



**Args:**

- <b>`username`</b>: username to be changed.
- <b>`server`</b>: to be used to create the user id.
- <b>`admin_access_token`</b>: server admin access token to call API.



**Raises:**

- <b>`ChangeUserAdminError`</b>: if something goes wrong while changing the user to be an admin.


---

<a href="../src/actions/change_user_admin.py#L17"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `ChangeUserAdminError`
Exception raised when something fails while running change-user-admin.

Attrs: msg (str): Explanation of the error.

<a href="../src/actions/change_user_admin.py#L24"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

```python
__init__(msg: str)
```

Initialize a new instance of the ChangeUserAdminError exception.



**Args:**

- <b>`msg`</b> (str): Explanation of the error.





Loading
Loading