chore(v1.1.8): cargo fmt --all (reviewer)
8 files needed re-wrapping after the F2 clippy-fix pass landed un-fmt'd. Pure cosmetic — no behavioral change. Re-runs of `cargo fmt --all -- --check` now exit clean. Reviewer-supplied per REVIEW.md §7; folded onto the branch to avoid a NEEDS-CHANGES round-trip on a purely mechanical fix.
This commit is contained in:
@@ -28,7 +28,7 @@ use async_trait::async_trait;
|
||||
use chrono::Utc;
|
||||
use picloud_shared::{
|
||||
AppId, AppUser, AppUserId, CreateUserInput, EmailError, EmailService, EmailTemplateOpts,
|
||||
GeneratedAccept, GeneratedSession, InviteOpts, Invitation, InvitationId, OutboundEmail,
|
||||
GeneratedAccept, GeneratedSession, Invitation, InvitationId, InviteOpts, OutboundEmail,
|
||||
Principal, SdkCallCx, ServiceEvent, ServiceEventEmitter, UpdateUserInput, UsersError,
|
||||
UsersListOpts, UsersListPage, UsersService,
|
||||
};
|
||||
@@ -84,7 +84,10 @@ impl UsersServiceConfig {
|
||||
pub fn from_env() -> Self {
|
||||
let default = Self::default();
|
||||
Self {
|
||||
session_ttl: env_duration_hours("PICLOUD_APP_USER_SESSION_TTL_HOURS", default.session_ttl),
|
||||
session_ttl: env_duration_hours(
|
||||
"PICLOUD_APP_USER_SESSION_TTL_HOURS",
|
||||
default.session_ttl,
|
||||
),
|
||||
session_absolute_ttl: env_duration_hours(
|
||||
"PICLOUD_APP_USER_SESSION_ABSOLUTE_HOURS",
|
||||
default.session_absolute_ttl,
|
||||
@@ -162,7 +165,11 @@ impl UsersServiceImpl {
|
||||
}
|
||||
}
|
||||
|
||||
async fn require(&self, principal: Option<&Principal>, cap: Capability) -> Result<(), UsersError> {
|
||||
async fn require(
|
||||
&self,
|
||||
principal: Option<&Principal>,
|
||||
cap: Capability,
|
||||
) -> Result<(), UsersError> {
|
||||
let Some(p) = principal else {
|
||||
// Public HTTP execution — script-as-gate; not denied here.
|
||||
return Ok(());
|
||||
@@ -192,7 +199,11 @@ impl UsersServiceImpl {
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_roles(&self, app_id: AppId, user_id: AppUserId) -> Result<Vec<String>, UsersError> {
|
||||
async fn fetch_roles(
|
||||
&self,
|
||||
app_id: AppId,
|
||||
user_id: AppUserId,
|
||||
) -> Result<Vec<String>, UsersError> {
|
||||
Ok(self.roles.list_for_user(app_id, user_id).await?)
|
||||
}
|
||||
|
||||
@@ -358,19 +369,14 @@ fn internal_cx(cx: &SdkCallCx) -> SdkCallCx {
|
||||
|
||||
#[async_trait]
|
||||
impl UsersService for UsersServiceImpl {
|
||||
async fn create(
|
||||
&self,
|
||||
cx: &SdkCallCx,
|
||||
input: CreateUserInput,
|
||||
) -> Result<AppUser, UsersError> {
|
||||
async fn create(&self, cx: &SdkCallCx, input: CreateUserInput) -> Result<AppUser, UsersError> {
|
||||
self.require(cx.principal.as_ref(), Capability::AppUsersWrite(cx.app_id))
|
||||
.await?;
|
||||
let email = validate_email(&input.email)?;
|
||||
validate_password(&input.password)?;
|
||||
let display_name = validate_display_name(input.display_name.as_deref())?;
|
||||
let password_hash = hash_password(&input.password).map_err(|e| {
|
||||
UsersError::Backend(format!("password hashing failed: {e}"))
|
||||
})?;
|
||||
let password_hash = hash_password(&input.password)
|
||||
.map_err(|e| UsersError::Backend(format!("password hashing failed: {e}")))?;
|
||||
let row = self
|
||||
.users
|
||||
.create(cx.app_id, &email, &password_hash, display_name.as_deref())
|
||||
@@ -443,11 +449,7 @@ impl UsersService for UsersServiceImpl {
|
||||
Ok(deleted)
|
||||
}
|
||||
|
||||
async fn list(
|
||||
&self,
|
||||
cx: &SdkCallCx,
|
||||
opts: UsersListOpts,
|
||||
) -> Result<UsersListPage, UsersError> {
|
||||
async fn list(&self, cx: &SdkCallCx, opts: UsersListOpts) -> Result<UsersListPage, UsersError> {
|
||||
self.require(cx.principal.as_ref(), Capability::AppUsersRead(cx.app_id))
|
||||
.await?;
|
||||
let limit = opts.limit.unwrap_or(50).clamp(1, 500);
|
||||
@@ -540,11 +542,7 @@ impl UsersService for UsersServiceImpl {
|
||||
}))
|
||||
}
|
||||
|
||||
async fn verify(
|
||||
&self,
|
||||
cx: &SdkCallCx,
|
||||
token: &str,
|
||||
) -> Result<Option<AppUser>, UsersError> {
|
||||
async fn verify(&self, cx: &SdkCallCx, token: &str) -> Result<Option<AppUser>, UsersError> {
|
||||
self.require(cx.principal.as_ref(), Capability::AppUsersRead(cx.app_id))
|
||||
.await?;
|
||||
self.resolve_session(cx.app_id, token).await
|
||||
@@ -626,10 +624,7 @@ impl UsersService for UsersServiceImpl {
|
||||
let Some(user_id) = self.verifications.consume(cx.app_id, &token_hash).await? else {
|
||||
return Ok(None);
|
||||
};
|
||||
let row = self
|
||||
.users
|
||||
.mark_email_verified(cx.app_id, user_id)
|
||||
.await?;
|
||||
let row = self.users.mark_email_verified(cx.app_id, user_id).await?;
|
||||
let roles = self.fetch_roles(cx.app_id, row.id).await?;
|
||||
let user = Self::to_app_user(row, roles);
|
||||
self.emit(cx, "email_verified", user.id).await;
|
||||
@@ -792,7 +787,11 @@ impl UsersService for UsersServiceImpl {
|
||||
// No require: the invitation token IS the authorization.
|
||||
validate_password(password)?;
|
||||
let token_hash = hash_token(token);
|
||||
let Some(consumed) = self.invitations.consume_by_token(cx.app_id, &token_hash).await? else {
|
||||
let Some(consumed) = self
|
||||
.invitations
|
||||
.consume_by_token(cx.app_id, &token_hash)
|
||||
.await?
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
@@ -1114,4 +1113,3 @@ impl UsersServiceImpl {
|
||||
Ok(Some(Self::to_app_user(row, roles)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user