Skip to content

Commit 99b7623

Browse files
authored
Merge pull request #148
feat!: Accept `auto_accept=true` on route `POST /v1/invitations`
2 parents ad3e8dc + 2ebb5bd commit 99b7623

File tree

8 files changed

+30
-55
lines changed

8 files changed

+30
-55
lines changed

crates/rest-api/src/features/invitations/invite_member.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// License: Mozilla Public License v2.0 (MPL v2.0)
55

66
#[cfg(debug_assertions)]
7-
use axum::extract::State;
7+
use axum::extract::{Query, State};
88
use axum::{http::HeaderValue, Json};
99
#[cfg(debug_assertions)]
1010
use axum_extra::either::Either;
@@ -55,22 +55,41 @@ pub struct InviteMemberRequest {
5555
pub contact: InvitationContact,
5656
}
5757

58+
#[cfg(debug_assertions)]
59+
#[derive(Deserialize)]
60+
pub struct InviteMemberQuery {
61+
#[serde(default)]
62+
pub auto_accept: bool,
63+
}
64+
5865
/// Invite a new member and auto-accept the invitation if enabled.
5966
pub async fn invite_member_route(
6067
#[cfg(debug_assertions)] State(AppState { db, .. }): State<AppState>,
6168
app_config: AppConfig,
6269
server_config: ServerConfig,
6370
notification_service: NotificationService,
6471
invitation_service: InvitationService,
72+
#[cfg(debug_assertions)] Query(InviteMemberQuery { auto_accept }): Query<InviteMemberQuery>,
6573
Json(req): Json<InviteMemberRequest>,
6674
) -> InviteMemberResponse {
75+
#[cfg(not(debug_assertions))]
6776
let invitation = invitation_service
6877
.invite_member(&app_config, &server_config, &notification_service, req)
6978
.await?;
79+
#[cfg(debug_assertions)]
80+
let invitation = invitation_service
81+
.invite_member(
82+
&app_config,
83+
&server_config,
84+
&notification_service,
85+
req,
86+
auto_accept,
87+
)
88+
.await?;
7089

7190
#[cfg(debug_assertions)]
7291
{
73-
if app_config.debug_only.automatically_accept_invitations {
92+
if auto_accept {
7493
let jid = invitation.jid;
7594
let resource_uri = format!("/v1/members/{jid}");
7695
let member = MemberRepository::get(&db, &jid).await?.unwrap();

crates/service/src/features/app_config/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ impl Default for ConfigDebug {
338338
#[cfg(debug_assertions)]
339339
#[derive(Debug, Clone, Deserialize, Default)]
340340
pub struct ConfigDebugOnly {
341-
#[serde(default)]
342-
pub automatically_accept_invitations: bool,
343341
/// When automatically accepting invitations during testing, one might want to authenticate
344342
/// the created member. With this flag turned on, the member's password will be their JID.
345343
#[serde(default)]

crates/service/src/features/invitations/invitation_service.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl InvitationService {
6262
server_config: &ServerConfig,
6363
notification_service: &NotificationService,
6464
form: impl Into<InviteMemberForm>,
65+
#[cfg(debug_assertions)] auto_accept: bool,
6566
) -> Result<Invitation, InviteMemberError> {
6667
let form = form.into();
6768
let jid = form.jid(&server_config)?;
@@ -136,11 +137,8 @@ impl InvitationService {
136137
})?;
137138

138139
#[cfg(debug_assertions)]
139-
if app_config.debug_only.automatically_accept_invitations {
140-
warn!(
141-
"Config `{}` is turned on. The created invitation will be automatically accepted.",
142-
stringify!(debug_only.automatically_accept_invitations),
143-
);
140+
if auto_accept {
141+
warn!("As requested, the created invitation will be automatically accepted.");
144142

145143
let password: SecretString = if app_config
146144
.debug_only

scripts/integration-test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ for arg in "$@"; do
106106
fi
107107

108108
case $arg in
109-
members|workspace)
110-
stepci_run "$test_file" test-auto_accept_invitations ;;
111109
*dns-configured-correctly-dynamic)
112110
DNS_ZONE_FILE="${DNS_ZONES_DIR:?}"/working-dynamic.zone stepci_run "$test_file" ;;
113111
*)

tests/integration/Prose-test-auto_accept_invitations.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/integration/Prose-test.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ pod_address = "pod@prose.org.local"
1313

1414
smtp_host = "mailpit"
1515
smtp_encrypt = false
16+
17+
[debug_only]
18+
insecure_password_on_auto_accept_invitation = true

tests/integration/step-ci/members.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ components:
236236
http:
237237
method: POST
238238
url: /v1/invitations
239+
params:
240+
auto_accept: true
239241
auth:
240242
bearer:
241243
token: ${{ captures.token }}

tests/integration/step-ci/workspace.yaml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before:
99
- $ref: "init.yaml#/components/steps/create_first_admin"
1010
- $ref: "init.yaml#/components/steps/init_workspace"
1111
- $ref: "init.yaml#/components/steps/log_admin_in"
12-
- $ref: "#/components/steps/add_member"
12+
- $ref: "members.yaml#/components/steps/add_member"
1313

1414
tests:
1515
getWorkspaceDetailsAsAdmin:
@@ -79,30 +79,6 @@ components:
7979
status: 200
8080
schema:
8181
$ref: openapi.json#/components/schemas/GetWorkspaceAccentColorResponse
82-
83-
add_member:
84-
name: Add member (via auto-accepted invitation)
85-
http:
86-
method: POST
87-
url: /v1/invitations
88-
auth:
89-
bearer:
90-
token: ${{ captures.token }}
91-
json:
92-
username: ${{ internet.userName | fake }}
93-
pre_assigned_role: MEMBER
94-
channel: email
95-
email_address: ${{ internet.email | fake }}
96-
captures:
97-
lastInvitationJid:
98-
jsonpath: $.jid
99-
check:
100-
status: 201
101-
headers:
102-
Content-Type: application/json
103-
Location: /.+/
104-
schema:
105-
$ref: openapi.json#/components/schemas/Member
10682
log_member_in:
10783
$ref: "invitations.yaml#/components/steps/log_last_invited_member_in"
10884

0 commit comments

Comments
 (0)