Skip to content

Commit 5db84c4

Browse files
Apply suggestions from code review
Co-authored-by: Aleksander <[email protected]>
1 parent fb87690 commit 5db84c4

File tree

6 files changed

+29
-28
lines changed

6 files changed

+29
-28
lines changed

src/db/models/enrollment.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl Token {
247247
}
248248

249249
let admin_id = self.admin_id.unwrap();
250-
debug!("Try to find admin using id {}", admin_id);
250+
debug!("Trying to find admin using id {admin_id}");
251251
let user = User::find_by_id(executor, admin_id).await?;
252252
debug!("Fetched admin {user:?}.");
253253
Ok(user)
@@ -392,16 +392,16 @@ impl User {
392392
mail_tx: UnboundedSender<Mail>,
393393
) -> Result<String, TokenError> {
394394
info!(
395-
"Start generating a new enrollment process for user {}.",
396-
self.username
395+
"User {} started a new enrollment process for user {}.",
396+
admin.username, self.username
397397
);
398398
debug!(
399399
"Notify user by mail about the enrollment process: {}",
400400
send_user_notification
401401
);
402-
debug!("Check is {} has a password.", self.username);
402+
debug!("Check if {} has a password.", self.username);
403403
if self.has_password() {
404-
debug!("User that you want to start enrollment process has already password.");
404+
debug!("User {} that you want to start enrollment process for already has a password.", self.username);
405405
return Err(TokenError::AlreadyActive);
406406
}
407407

@@ -497,7 +497,7 @@ impl User {
497497
send_user_notification: bool,
498498
mail_tx: UnboundedSender<Mail>,
499499
) -> Result<String, TokenError> {
500-
info!("Start a new desktop activation for user {}", self.username);
500+
info!("User {} starting a new desktop activation for user {}", admin.username, self.username);
501501
debug!(
502502
"Notify {} by mail about the enrollment process: {}",
503503
self.username, send_user_notification

src/grpc/enrollment.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl EnrollmentServer {
136136
let user = enrollment.fetch_user(&self.pool).await?;
137137
let admin = enrollment.fetch_admin(&self.pool).await?;
138138

139-
debug!("Check is {} an active user.", user.username);
139+
debug!("Check if {} is an active user.", user.username);
140140
if !user.is_active {
141141
warn!(
142142
"Can't start enrollment for disabled user {}.",
@@ -210,7 +210,7 @@ impl EnrollmentServer {
210210

211211
Ok(response)
212212
} else {
213-
debug!("Invalid an enrollment token, the token does not have specified type.");
213+
debug!("Invalid enrollment token, the token does not have specified type.");
214214
Err(Status::permission_denied("invalid token"))
215215
}
216216
}
@@ -236,26 +236,26 @@ impl EnrollmentServer {
236236
debug!("Ip address {}, device info {device_info:?}", ip_address);
237237

238238
// check if password is strong enough
239-
debug!("Verify is password strong enough to complete the activating user process.");
239+
debug!("Verify if password is strong enough to complete the user activation process.");
240240
if let Err(err) = check_password_strength(&request.password) {
241241
error!("Password not strong enough: {err}");
242242
return Err(Status::invalid_argument("password not strong enough"));
243243
}
244-
debug!("Password is strong enough to complete the activating user process.");
244+
debug!("Password is strong enough to complete the user activation process.");
245245

246246
// fetch related users
247247
let mut user = enrollment.fetch_user(&self.pool).await?;
248248
debug!(
249-
"Fetching user {} data to check is the user has already password.",
249+
"Fetching user {} data to check if the user already has a password.",
250250
user.username
251251
);
252252
if user.has_password() {
253253
error!("User {} already activated", user.username);
254254
return Err(Status::invalid_argument("user already activated"));
255255
}
256-
debug!("User doesn't have a password yet. Continue activating user process...");
256+
debug!("User doesn't have a password yet. Continue user activation process...");
257257

258-
debug!("Verify is the user active or disabled.");
258+
debug!("Verify if the user is active or disabled.");
259259
if !user.is_active {
260260
warn!(
261261
"Can't finalize enrollment for disabled user {}",
@@ -278,7 +278,7 @@ impl EnrollmentServer {
278278
error!("Failed to update user {}: {err}", user.username);
279279
Status::internal("unexpected error")
280280
})?;
281-
debug!("Updating user details ends with success.");
281+
debug!("Updating user details ended with success.");
282282

283283
// sync with LDAP
284284
debug!("Add user to ldap: {}.", self.ldap_feature_active);
@@ -294,7 +294,7 @@ impl EnrollmentServer {
294294
error!("Failed to get settings");
295295
Status::internal("unexpected error")
296296
})?;
297-
debug!("Successfully retrive settings.");
297+
debug!("Successfully retrived settings.");
298298

299299
// send welcome email
300300
debug!("Try to send welcome email...");
@@ -311,7 +311,7 @@ impl EnrollmentServer {
311311

312312
// send success notification to admin
313313
debug!(
314-
"Trying fetch admin data from the token to send notification about activating user."
314+
"Trying to fetch admin data from the token to send notification about activating user."
315315
);
316316
let admin = enrollment.fetch_admin(&mut *transaction).await?;
317317

@@ -348,7 +348,7 @@ impl EnrollmentServer {
348348
let user = enrollment.fetch_user(&self.pool).await?;
349349

350350
// add device
351-
debug!("Verifying is user active or disabled.");
351+
debug!("Verifying if user is active or disabled.");
352352
if !user.is_active {
353353
error!("Can't create device for a disabled user {}", user.username);
354354
return Err(Status::invalid_argument(
@@ -368,15 +368,15 @@ impl EnrollmentServer {
368368
}
369369
debug!("Ip address {}, device info {device_info:?}", ip_address);
370370

371-
debug!("Start validating pubkey for create device process...");
371+
debug!("Start validating pubkey for device creation process...");
372372
Device::validate_pubkey(&request.pubkey).map_err(|_| {
373373
error!("Invalid pubkey {}", request.pubkey);
374374
Status::invalid_argument("invalid pubkey")
375375
})?;
376376
debug!("Pubkey is validated.");
377377

378378
// Make sure there is no device with the same pubkey, such state may lead to unexpected issues
379-
debug!("Check is there a device that has the same pubey.");
379+
debug!("Check if there is a device that has the same pubey.");
380380
if let Some(device) = Device::find_by_pubkey(&self.pool, &request.pubkey)
381381
.await
382382
.map_err(|_| {

src/grpc/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ pub async fn run_grpc_bidi_stream(
388388
break 'message;
389389
}
390390
Ok(Some(received)) => {
391-
info!("Received message from proxy {received:?}");
391+
info!("Received message from proxy.");
392+
debug!("Received the following message from proxy: {received:?}");
392393
let payload = match received.payload {
393394
// rpc StartEnrollment (EnrollmentStartRequest) returns (EnrollmentStartResponse)
394395
Some(core_request::Payload::EnrollmentStart(request)) => {

src/handlers/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub async fn user_for_admin_or_self(
291291
username: &str,
292292
) -> Result<User, WebError> {
293293
if session.user.username == username || session.is_admin {
294-
debug!("The user meets one or both of these conditions: 1) the user from the current session has admin privileges, 2) the user only wants for self to perform this operation.");
294+
debug!("The user meets one or both of these conditions: 1) the user from the current session has admin privileges, 2) the user performs this operation on themself.");
295295
match User::find_by_username(pool, username).await? {
296296
Some(user) => {
297297
debug!("User {} has been found in database.", user.username);
@@ -305,7 +305,7 @@ pub async fn user_for_admin_or_self(
305305
}
306306
}
307307
} else {
308-
debug!("User from the current session don't have enough privileges to do this operation.");
308+
debug!("User from the current session doesn't have enough privileges to do this operation.");
309309
Err(WebError::Forbidden("requires privileged access".into()))
310310
}
311311
}

src/handlers/user.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ pub async fn start_enrollment(
396396
)
397397
.await?;
398398

399-
debug!("Try to submit transaction to save the enrollment token into the databse.");
399+
debug!("Try to commit transaction to save the enrollment token into the databse.");
400400
transaction.commit().await?;
401-
debug!("Transaction submitted.");
401+
debug!("Transaction committed.");
402402

403403
info!(
404404
"The enrollment process for {} has ended with success.",
@@ -446,7 +446,7 @@ pub async fn start_remote_desktop_configuration(
446446
Json(data): Json<StartEnrollmentRequest>,
447447
) -> ApiResult {
448448
debug!(
449-
"User {} has started a new desktop activation request.",
449+
"User {} has started a new desktop activation for {username}.",
450450
session.user.username
451451
);
452452

@@ -485,7 +485,7 @@ pub async fn start_remote_desktop_configuration(
485485
debug!("Transaction submitted.");
486486

487487
info!(
488-
"User {} added a new desktop activation.",
488+
"User {} started a new desktop activation.",
489489
session.user.username
490490
);
491491
debug!(
@@ -620,7 +620,7 @@ pub async fn modify_user(
620620
.await?
621621
{
622622
debug!(
623-
"User {} has started a new enrollment request.",
623+
"User {} changed {username} groups or status, syncing allowed network devices.",
624624
session.user.username
625625
);
626626
let networks = WireguardNetwork::all(&mut *transaction).await?;

src/templates.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn enrollment_start_mail(
9090
mut enrollment_service_url: Url,
9191
enrollment_token: &str,
9292
) -> Result<String, TemplateError> {
93-
debug!("Render a enrollment start mail template for the user.");
93+
debug!("Render an enrollment start mail template for the user.");
9494
let (mut tera, mut context) = get_base_tera(Some(context), None, None, None)?;
9595

9696
// add required context

0 commit comments

Comments
 (0)