-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: room handlers for admin and client API (#23)
Hopefully the commit messages are self-explanatory <!-- Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. --> --------- Co-authored-by: Esteban Borai <[email protected]>
- Loading branch information
Showing
43 changed files
with
1,807 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,26 @@ use url::Url; | |
use uuid::Uuid; | ||
use validator::{Validate, ValidationError}; | ||
|
||
use matrix::admin::resources::user::{ | ||
ListUsersParams, LoginAsUserDto, ThreePid, User as MatrixUser, UserCreateDto, | ||
use matrix::{ | ||
admin::resources::{ | ||
user::{ListUsersParams, LoginAsUserDto, ThreePid, User as MatrixUser, UserCreateDto}, | ||
user_id::UserId, | ||
}, | ||
Client as MatrixAdminClient, | ||
}; | ||
use matrix::admin::resources::user_id::UserId; | ||
use matrix::Client as MatrixAdminClient; | ||
|
||
use crate::auth::service::AuthService; | ||
use crate::mail::service::{EmailTemplate, MailService}; | ||
use crate::util::secret::Secret; | ||
use crate::util::time::timestamp; | ||
use crate::{Error, Result}; | ||
use crate::{ | ||
auth::service::AuthService, | ||
mail::service::{EmailTemplate, MailService}, | ||
util::{secret::Secret, time::timestamp}, | ||
Error, Result, | ||
}; | ||
|
||
use super::error::AccountErrorCode; | ||
use super::model::Account; | ||
use super::{error::AccountErrorCode, model::Account}; | ||
|
||
const DEFAULT_AVATAR_URL: &str = "https://via.placeholder.com/150"; | ||
const MIN_USERNAME_LENGTH: usize = 3; | ||
const MAX_USERNAME_LENGTH: usize = 12; | ||
const MIN_USERNAME_LENGTH: usize = 1; | ||
const MAX_USERNAME_LENGTH: usize = 255; | ||
const MIN_PASSWORD_LENGTH: usize = 8; | ||
|
||
#[derive(Debug, Validate)] | ||
|
@@ -191,8 +193,8 @@ impl AccountService { | |
Ok(account) | ||
} | ||
|
||
/// Registers a new user account in Matrix Server without verifying the email ownership. | ||
/// This shuld be used for testing purposes only. | ||
/// Registers a new user account in Matrix Server without verifying the | ||
/// email ownership. This shuld be used for testing purposes only. | ||
#[instrument(skip(self, dto))] | ||
pub async fn register_unverified(&self, dto: CreateUnverifiedAccountDto) -> Result<Account> { | ||
dto.validate().map_err(|err| { | ||
|
@@ -318,29 +320,29 @@ mod test { | |
#[test] | ||
fn ensure_username_is_not_too_short() { | ||
let dto = CreateAccountDto { | ||
username: "ab".to_string(), | ||
username: "".to_string(), | ||
password: Secret::new("password"), | ||
email: "[email protected]".to_string(), | ||
code: Secret::new("1234"), | ||
session: Uuid::new_v4(), | ||
}; | ||
let err = dto.validate().err().unwrap(); | ||
|
||
assert_eq!(err.to_string(), "username is too short"); | ||
assert!(err.to_string().contains("username is too short")); | ||
} | ||
|
||
#[test] | ||
fn ensure_username_is_not_too_long() { | ||
let dto = CreateAccountDto { | ||
username: "abbeyroadismyfavoritealbum".to_string(), | ||
username: (0..300).map(|_| "a").collect(), | ||
password: Secret::new("password"), | ||
email: "[email protected]".to_string(), | ||
code: Secret::new("1234"), | ||
session: Uuid::new_v4(), | ||
}; | ||
let err = dto.validate().err().unwrap(); | ||
|
||
assert_eq!(err.to_string(), "username is too long"); | ||
assert!(err.to_string().contains("username is too long")); | ||
} | ||
|
||
#[test] | ||
|
@@ -354,7 +356,7 @@ mod test { | |
}; | ||
let err = dto.validate().err().unwrap(); | ||
|
||
assert_eq!(err.to_string(), "username cannot contain spaces"); | ||
assert!(err.to_string().contains("username cannot contain spaces")); | ||
} | ||
|
||
#[test] | ||
|
@@ -368,6 +370,8 @@ mod test { | |
}; | ||
let err = dto.validate().err().unwrap(); | ||
|
||
assert_eq!(err.to_string(), "username cannot contain uppercase letters"); | ||
assert!(err | ||
.to_string() | ||
.contains("username cannot contain uppercase letters")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod room; | ||
pub mod token; | ||
pub mod user; | ||
pub mod user_id; |
Oops, something went wrong.