Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions resources/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"validation_required": "%{attribute} is a required field.",
"validation_count": "The given %{attribute} has to be unique.",
"email_password_not_matched": "Email and Password did not match.",
"validation_invalid_local": "The given %{provided_locale} is not valid locale. System is not supported for this locale.",
"admin_user_forbidden": "You are not allowed to perform this request. Please check with your administrator."
}
4 changes: 3 additions & 1 deletion resources/locales/fr.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"name": "french"
"name": "french",
"email_address_not_valid": "french Email address is not valid",
"validation_required": "french %{attribute} is a required field."
}
24 changes: 16 additions & 8 deletions src/api/admin_user_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ impl AdminUser for AdminUserApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let request_data = request.into_inner();
request_data.validate(&self.state).await?;
request_data.validate(&self.state, user_locale).await?;


match self
Expand Down Expand Up @@ -178,8 +179,9 @@ impl AdminUser for AdminUserApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate().await?;
req.validate(user_locale).await?;

match self
.state
Expand Down Expand Up @@ -282,8 +284,9 @@ impl AdminUser for AdminUserApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate(&self.state).await?;
req.validate(&self.state, user_locale).await?;

let created_role_request = CreatableRole {
name: req.name,
Expand Down Expand Up @@ -355,8 +358,9 @@ impl AdminUser for AdminUserApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate()?;
req.validate(user_locale)?;

match self
.state
Expand Down Expand Up @@ -394,8 +398,9 @@ impl AdminUser for AdminUserApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate(&self.state).await?;
req.validate(&self.state, user_locale).await?;

match self
.state
Expand Down Expand Up @@ -430,8 +435,9 @@ impl AdminUser for AdminUserApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate()?;
req.validate(user_locale)?;

match self
.state
Expand Down Expand Up @@ -469,8 +475,9 @@ impl AdminUser for AdminUserApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate()?;
req.validate(user_locale)?;

match self
.state
Expand Down Expand Up @@ -508,8 +515,9 @@ impl AdminUser for AdminUserApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate()?;
req.validate(user_locale)?;

match self
.state
Expand Down
18 changes: 12 additions & 6 deletions src/api/content_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ impl Content for ContentApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate(&self.state).await?;
req.validate(&self.state, user_locale).await?;

match self
.state
Expand Down Expand Up @@ -174,8 +175,9 @@ impl Content for ContentApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate().await?;
req.validate(user_locale).await?;

match self
.state
Expand Down Expand Up @@ -213,8 +215,9 @@ impl Content for ContentApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate(&self.state).await?;
req.validate(&self.state, user_locale).await?;

match self
.state
Expand Down Expand Up @@ -282,8 +285,9 @@ impl Content for ContentApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate(&self.state).await?;
req.validate(&self.state, user_locale).await?;

match self
.state
Expand Down Expand Up @@ -318,8 +322,9 @@ impl Content for ContentApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate()?;
req.validate(user_locale)?;

match self
.state
Expand Down Expand Up @@ -354,8 +359,9 @@ impl Content for ContentApi {
)
.await?;

let user_locale = logged_in_user.locale.clone();
let req = request.into_inner();
req.validate()?;
req.validate(user_locale)?;

match self
.state
Expand Down
1 change: 1 addition & 0 deletions src/repositories/security_alert_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl SecurityAlertRepository {
createable_security_alert_model: CreateSecurityAlertModel,
) -> Result<SecurityAlertModel> {
// Validate the input

createable_security_alert_model.validate()?;

let sql = r"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

impl ChangeAdminUserPasswordRequest {
/// validate
pub fn validate(&self) -> crate::error::Result<()> {
pub fn validate(&self, locale: String) -> crate::error::Result<()> {

Check warning

Code scanning / clippy

docs for function returning Result missing # Errors section Warning

docs for function returning Result missing # Errors section

Check warning

Code scanning / clippy

this argument is passed by value, but not consumed in the function body Warning

this argument is passed by value, but not consumed in the function body

Check warning

Code scanning / clippy

this argument is passed by value, but not consumed in the function body Warning

this argument is passed by value, but not consumed in the function body
let mut errors: Vec<ErrorMessage> = vec![];
let mut valid = true;

if !self.password.required()? {
let error_message = ErrorMessage {
key: String::from("password"),
message: t!("validation_required", attribute = t!("password")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("password", locale = locale)).to_string(),
};
valid = false;
errors.push(error_message);
Expand All @@ -22,7 +22,7 @@
if !self.new_password.required()? {
let error_message = ErrorMessage {
key: String::from("new_password"),
message: t!("validation_required", attribute = t!("new_password")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("new_password", locale = locale)).to_string(),
};
valid = false;
errors.push(error_message);
Expand All @@ -31,7 +31,7 @@
if !self.confirm_password.required()? {
let error_message = ErrorMessage {
key: String::from("confirm_password"),
message: t!("validation_required", attribute = t!("confirm_password")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("confirm_password", locale = locale)).to_string(),
};
valid = false;
errors.push(error_message);
Expand All @@ -40,7 +40,7 @@
if self.new_password != self.confirm_password {
let error_message = ErrorMessage {
key: String::from("confirm_password"),
message: t!("validation_confirmed", attribute = t!("confirm_password")).to_string(),
message: t!("validation_confirmed", locale = locale, attribute = t!("confirm_password", locale = locale)).to_string(),
};
valid = false;
errors.push(error_message);
Expand Down
4 changes: 2 additions & 2 deletions src/requests/admin_user_request/delete_admin_user_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

impl DeleteAdminUserRequest {
/// validate
pub fn validate(&self) -> crate::error::Result<()> {
pub fn validate(&self, locale: String) -> crate::error::Result<()> {

Check warning

Code scanning / clippy

docs for function returning Result missing # Errors section Warning

docs for function returning Result missing # Errors section

Check warning

Code scanning / clippy

this argument is passed by value, but not consumed in the function body Warning

this argument is passed by value, but not consumed in the function body

Check warning

Code scanning / clippy

this argument is passed by value, but not consumed in the function body Warning

this argument is passed by value, but not consumed in the function body
let mut errors: Vec<ErrorMessage> = vec![];
let mut valid = true;

if !self.admin_user_id.required()? {
let error_message = ErrorMessage {
key: String::from("admin_user"),
message: t!("validation_required", attribute = t!("admin_user")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("admin_user", locale = locale)).to_string(),
};
valid = false;
errors.push(error_message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

impl DeleteRoleRequest {
/// validate
pub fn validate(&self) -> crate::error::Result<()> {
pub fn validate(&self, locale: String) -> crate::error::Result<()> {

Check warning

Code scanning / clippy

docs for function returning Result missing # Errors section Warning

docs for function returning Result missing # Errors section

Check warning

Code scanning / clippy

this argument is passed by value, but not consumed in the function body Warning

this argument is passed by value, but not consumed in the function body

Check warning

Code scanning / clippy

this argument is passed by value, but not consumed in the function body Warning

this argument is passed by value, but not consumed in the function body
let mut errors: Vec<ErrorMessage> = vec![];
let mut valid = true;

if !self.role_id.required()? {
let error_message = ErrorMessage {
key: String::from("role_id"),
message: t!("validation_required", attribute = t!("role_id")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("role_id", locale = locale)).to_string(),
};
valid = false;
errors.push(error_message);
Expand Down
3 changes: 3 additions & 0 deletions src/requests/admin_user_request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ pub mod update_admin_user_request;
pub mod update_role_request;
/// change admin user password request
pub mod change_admin_user_password_request;

/// delete role request
pub mod delete_role_request;
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

impl PutRoleIdentifierRequest {
/// validate
pub async fn validate(&self, state: &AvoRedState) -> crate::error::Result<()> {
pub async fn validate(&self, state: &AvoRedState, locale: String) -> crate::error::Result<()> {

Check warning

Code scanning / clippy

docs for function returning Result missing # Errors section Warning

docs for function returning Result missing # Errors section
let mut errors: Vec<ErrorMessage> = vec![];
let mut valid = true;

if self.identifier.is_empty() {
let error_message = ErrorMessage {
key: String::from("identifier"),
message: t!("validation_required", attribute = t!("identifier")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("identifier", locale = locale)).to_string(),
};

valid = false;
Expand All @@ -27,7 +27,7 @@
if role_identifier_count.total > 0 {
let error_message = ErrorMessage {
key: String::from("email"),
message: t!("validation_count", attribute = t!("email")).to_string(),
message: t!("validation_count", locale = locale, attribute = t!("email", locale = locale)).to_string(),
};

valid = false;
Expand Down
14 changes: 7 additions & 7 deletions src/requests/admin_user_request/store_admin_user_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

impl StoreAdminUserRequest {
/// validate
pub async fn validate(&self, state: &AvoRedState) -> crate::error::Result<()> {
pub async fn validate(&self, state: &AvoRedState, locale: String) -> crate::error::Result<()> {

Check warning

Code scanning / clippy

docs for function returning Result missing # Errors section Warning

docs for function returning Result missing # Errors section
let mut errors: Vec<ErrorMessage> = vec![];
let mut valid = true;

if !self.email.required()? {
let error_message = ErrorMessage {
key: String::from("email"),
message: t!("validation_required", attribute = t!("email")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("email", locale = locale)).to_string(),
};
valid = false;
errors.push(error_message);
Expand All @@ -22,7 +22,7 @@
if !self.email.validate_email()? {
let error_message = ErrorMessage {
key: String::from("email"),
message: t!("email_address_not_valid").to_string(),
message: t!("email_address_not_valid", locale = locale).to_string(),
};

valid = false;
Expand All @@ -37,7 +37,7 @@
if admin_user_model.total > 0 {
let error_message = ErrorMessage {
key: String::from("email"),
message: t!("validation_count", attribute = t!("email")).to_string(),
message: t!("validation_count", locale = locale, attribute = t!("email", locale = locale)).to_string(),
};

errors.push(error_message);
Expand All @@ -47,7 +47,7 @@
if !self.password.required()? {
let error_message = ErrorMessage {
key: String::from("password"),
message: t!("validation_required", attribute = t!("password")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("password", locale = locale)).to_string(),
};

valid = false;
Expand All @@ -57,7 +57,7 @@
if self.password != self.confirm_password {
let error_message = ErrorMessage {
key: String::from("password"),
message: t!("password_match_error").to_string(),
message: t!("password_match_error", locale = locale).to_string(),
};

valid = false;
Expand All @@ -70,7 +70,7 @@
if !locale_path.exists() {
let error_message = ErrorMessage {
key: String::from("locale"),
message: t!("validation_invalid", attribute = t!("locale")).to_string(),
message: t!("validation_invalid", locale = locale , attribute = t!("locale", locale = locale)).to_string(),
};

valid = false;
Expand Down
8 changes: 4 additions & 4 deletions src/requests/admin_user_request/store_role_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

impl StoreRoleRequest {
/// validate
pub async fn validate(&self, state: &AvoRedState) -> crate::error::Result<()> {
pub async fn validate(&self, state: &AvoRedState, locale: String) -> crate::error::Result<()> {

Check warning

Code scanning / clippy

docs for function returning Result missing # Errors section Warning

docs for function returning Result missing # Errors section
let mut errors: Vec<ErrorMessage> = vec![];
let mut valid = true;

if self.name.is_empty() {
let error_message = ErrorMessage {
key: String::from("name"),
message: t!("validation_required", attribute = t!("name")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("name", locale = locale)).to_string(),
};

valid = false;
Expand All @@ -22,7 +22,7 @@
if self.identifier.is_empty() {
let error_message = ErrorMessage {
key: String::from("identifier"),
message: t!("validation_required", attribute = t!("identifier")).to_string(),
message: t!("validation_required", locale = locale, attribute = t!("identifier", locale = locale)).to_string(),
};

valid = false;
Expand All @@ -37,7 +37,7 @@
if role_identifier_count.total > 0 {
let error_message = ErrorMessage {
key: String::from("email"),
message: t!("validation_count", attribute = t!("email")).to_string(),
message: t!("validation_count", locale = locale, attribute = t!("email", locale = locale)).to_string(),
};

valid = false;
Expand Down
Loading
Loading