Skip to content

Commit

Permalink
Support for external email addresses on mailing lists (stalwartlabs/m…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Nov 13, 2024
1 parent 2acc89c commit 8d49089
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/pages/directory/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
stacked_badge::StackedBadge,
stacked_input::StackedInput,
tab::Tab,
Form, FormButtonBar, FormElement, FormItem, FormSection,
Form, FormButtonBar, FormElement, FormItem, FormSection, ValidateCb,
},
messages::alert::{use_alerts, Alert},
skeleton::Skeleton,
Expand Down Expand Up @@ -840,6 +840,30 @@ pub fn PrincipalEdit() -> impl IntoView {
/>

</FormItem>
<FormItem
label="External Members"
hide=Signal::derive(move || {
!matches!(selected_type.get(), PrincipalType::List)
})
>

<StackedBadge
color=Color::Red
element=FormElement::new("external-members", data)
add_button_text="Add e-mail".to_string()
validate_item=Callback::new(move |
(value, cb): (String, ValidateCb)|
{
let email = value.trim().to_lowercase();
if email.contains('@') && email.contains('.') {
cb.call(Ok(email));
} else {
cb.call(Err("Please enter a valid e-mail".to_string()))
}
})
/>

</FormItem>
</FormSection>

<FormSection>
Expand Down Expand Up @@ -1094,6 +1118,7 @@ impl FormData {
principal.disabled_permissions.as_string_list(),
),
("urls", principal.urls.as_string_list()),
("external-members", principal.external_members.as_string_list()),
] {
self.array_set(key, list.iter());
}
Expand Down Expand Up @@ -1156,6 +1181,7 @@ impl FormData {
("enabled-permissions", &mut principal.enabled_permissions),
("disabled-permissions", &mut principal.disabled_permissions),
("urls", &mut principal.urls),
("external-members", &mut principal.external_members)
] {
*list = PrincipalValue::StringList(
self.array_value(key).map(|m| m.to_string()).collect(),
Expand Down Expand Up @@ -1219,6 +1245,13 @@ impl Builder<Schemas, ()> {
[Validator::IsEmail],
)
.build()
.new_field("external-members")
.typ(Type::Array)
.input_check(
[Transformer::Trim, Transformer::Lowercase],
[Validator::IsEmail],
)
.build()
.new_field("urls")
.typ(Type::Array)
.input_check([Transformer::Trim], [Validator::IsUrl])
Expand Down
10 changes: 10 additions & 0 deletions src/pages/directory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ pub struct Principal {
#[serde(default, skip_serializing_if = "PrincipalValue::is_none")]
#[serde(rename = "disabledPermissions")]
pub disabled_permissions: PrincipalValue,

#[serde(default, skip_serializing_if = "PrincipalValue::is_none")]
#[serde(rename = "externalMembers")]
pub external_members: PrincipalValue,
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -117,6 +121,7 @@ pub enum PrincipalField {
DisabledPermissions,
Picture,
Urls,
ExternalMembers,
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
Expand Down Expand Up @@ -240,6 +245,11 @@ impl Principal {

for (field, current, change) in [
(PrincipalField::Emails, current.emails, changes.emails),
(
PrincipalField::ExternalMembers,
current.external_members,
changes.external_members,
),
(
PrincipalField::MemberOf,
current.member_of,
Expand Down

0 comments on commit 8d49089

Please sign in to comment.