Skip to content

Commit 93b15ac

Browse files
committed
refactor: [#615] renamed variables to maybe_user_id
1 parent e614e2f commit 93b15ac

File tree

13 files changed

+62
-52
lines changed

13 files changed

+62
-52
lines changed

src/services/about.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ impl Service {
2424
///
2525
/// * The user does not have the required permissions.
2626
/// * There is an error authorizing the action.
27-
pub async fn get_about_page(&self, opt_user_id: Option<UserId>) -> Result<String, ServiceError> {
27+
pub async fn get_about_page(&self, maybe_user_id: Option<UserId>) -> Result<String, ServiceError> {
2828
self.authorization_service
29-
.authorize(ACTION::GetAboutPage, opt_user_id)
29+
.authorize(ACTION::GetAboutPage, maybe_user_id)
3030
.await?;
3131

3232
let html = r#"
@@ -58,9 +58,9 @@ impl Service {
5858
///
5959
/// * The user does not have the required permissions.
6060
/// * There is an error authorizing the action.
61-
pub async fn get_license_page(&self, opt_user_id: Option<UserId>) -> Result<String, ServiceError> {
61+
pub async fn get_license_page(&self, maybe_user_id: Option<UserId>) -> Result<String, ServiceError> {
6262
self.authorization_service
63-
.authorize(ACTION::GetLicensePage, opt_user_id)
63+
.authorize(ACTION::GetLicensePage, maybe_user_id)
6464
.await?;
6565

6666
let html = r#"

src/services/authorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ impl Service {
7474
/// Will return an error if:
7575
/// - The user is not authorized to perform the action.
7676
77-
pub async fn authorize(&self, action: ACTION, opt_user_id: Option<UserId>) -> std::result::Result<(), ServiceError> {
78-
let role = self.get_role(opt_user_id).await;
77+
pub async fn authorize(&self, action: ACTION, maybe_user_id: Option<UserId>) -> std::result::Result<(), ServiceError> {
78+
let role = self.get_role(maybe_user_id).await;
7979

8080
let enforcer = self.casbin_enforcer.enforcer.read().await;
8181

src/services/category.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ impl Service {
8787
///
8888
/// * The user does not have the required permissions.
8989
/// * There is a database error retrieving the categories.
90-
pub async fn get_categories(&self, opt_user_id: Option<UserId>) -> Result<Vec<Category>, ServiceError> {
90+
pub async fn get_categories(&self, maybe_user_id: Option<UserId>) -> Result<Vec<Category>, ServiceError> {
9191
self.authorization_service
92-
.authorize(ACTION::GetCategories, opt_user_id)
92+
.authorize(ACTION::GetCategories, maybe_user_id)
9393
.await?;
9494

9595
self.category_repository

src/services/proxy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ impl Service {
3939
/// * The image is too big.
4040
/// * The user quota is met.
4141
#[allow(clippy::missing_panics_doc)]
42-
pub async fn get_image_by_url(&self, url: &str, opt_user_id: Option<UserId>) -> Result<Bytes, Error> {
42+
pub async fn get_image_by_url(&self, url: &str, maybe_user_id: Option<UserId>) -> Result<Bytes, Error> {
4343
self.authorization_service
44-
.authorize(ACTION::GetImageByUrl, opt_user_id)
44+
.authorize(ACTION::GetImageByUrl, maybe_user_id)
4545
.await
4646
.map_err(|_| Error::Unauthenticated)?;
4747

48-
// The unwrap should never panic as if the opt_user_id is none, an authorization error will be returned and handled at the method above
49-
self.image_cache_service.get_image_by_url(url, opt_user_id.unwrap()).await
48+
// The unwrap should never panic as if the maybe_user_id is none, an authorization error will be returned and handled at the method above
49+
self.image_cache_service.get_image_by_url(url, maybe_user_id.unwrap()).await
5050
}
5151
}

src/services/settings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ impl Service {
6262
/// # Errors
6363
///
6464
/// It returns an error if the user does not have the required permissions.
65-
pub async fn get_public(&self, opt_user_id: Option<UserId>) -> Result<ConfigurationPublic, ServiceError> {
65+
pub async fn get_public(&self, maybe_user_id: Option<UserId>) -> Result<ConfigurationPublic, ServiceError> {
6666
self.authorization_service
67-
.authorize(ACTION::GetPublicSettings, opt_user_id)
67+
.authorize(ACTION::GetPublicSettings, maybe_user_id)
6868
.await?;
6969

7070
let settings_lock = self.configuration.get_all().await;

src/services/tag.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ impl Service {
7777
///
7878
/// * The user does not have the required permissions.
7979
/// * There is a database error retrieving the tags.
80-
pub async fn get_tags(&self, opt_user_id: Option<UserId>) -> Result<Vec<TorrentTag>, ServiceError> {
81-
self.authorization_service.authorize(ACTION::GetTags, opt_user_id).await?;
80+
pub async fn get_tags(&self, maybe_user_id: Option<UserId>) -> Result<Vec<TorrentTag>, ServiceError> {
81+
self.authorization_service.authorize(ACTION::GetTags, maybe_user_id).await?;
8282

8383
self.tag_repository.get_all().await.map_err(|_| ServiceError::DatabaseError)
8484
}

src/services/torrent.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,10 @@ impl Index {
262262
///
263263
/// This function will return an error if unable to get the torrent from the
264264
/// database.
265-
pub async fn get_torrent(&self, info_hash: &InfoHash, opt_user_id: Option<UserId>) -> Result<Torrent, ServiceError> {
266-
self.authorization_service.authorize(ACTION::GetTorrent, opt_user_id).await?;
265+
pub async fn get_torrent(&self, info_hash: &InfoHash, maybe_user_id: Option<UserId>) -> Result<Torrent, ServiceError> {
266+
self.authorization_service
267+
.authorize(ACTION::GetTorrent, maybe_user_id)
268+
.await?;
267269

268270
let mut torrent = self.torrent_repository.get_by_info_hash(info_hash).await?;
269271

@@ -275,7 +277,7 @@ impl Index {
275277

276278
if !tracker_is_private {
277279
torrent.include_url_as_main_tracker(&tracker_url);
278-
} else if let Some(authenticated_user_id) = opt_user_id {
280+
} else if let Some(authenticated_user_id) = maybe_user_id {
279281
let personal_announce_url = self.tracker_service.get_personal_announce_url(authenticated_user_id).await?;
280282
torrent.include_url_as_main_tracker(&personal_announce_url);
281283
} else {
@@ -331,16 +333,16 @@ impl Index {
331333
pub async fn get_torrent_info(
332334
&self,
333335
info_hash: &InfoHash,
334-
opt_user_id: Option<UserId>,
336+
maybe_user_id: Option<UserId>,
335337
) -> Result<TorrentResponse, ServiceError> {
336338
self.authorization_service
337-
.authorize(ACTION::GetTorrentInfo, opt_user_id)
339+
.authorize(ACTION::GetTorrentInfo, maybe_user_id)
338340
.await?;
339341

340342
let torrent_listing = self.torrent_listing_generator.one_torrent_by_info_hash(info_hash).await?;
341343

342344
let torrent_response = self
343-
.build_full_torrent_response(torrent_listing, info_hash, opt_user_id)
345+
.build_full_torrent_response(torrent_listing, info_hash, maybe_user_id)
344346
.await?;
345347

346348
Ok(torrent_response)
@@ -354,10 +356,10 @@ impl Index {
354356
pub async fn generate_torrent_info_listing(
355357
&self,
356358
request: &ListingRequest,
357-
opt_user_id: Option<UserId>,
359+
maybe_user_id: Option<UserId>,
358360
) -> Result<TorrentsResponse, ServiceError> {
359361
self.authorization_service
360-
.authorize(ACTION::GenerateTorrentInfoListing, opt_user_id)
362+
.authorize(ACTION::GenerateTorrentInfoListing, maybe_user_id)
361363
.await?;
362364

363365
let torrent_listing_specification = self.listing_specification_from_user_request(request).await;
@@ -484,7 +486,7 @@ impl Index {
484486
&self,
485487
torrent_listing: TorrentListing,
486488
info_hash: &InfoHash,
487-
opt_user_id: Option<UserId>,
489+
maybe_user_id: Option<UserId>,
488490
) -> Result<TorrentResponse, ServiceError> {
489491
let torrent_id: i64 = torrent_listing.torrent_id;
490492

@@ -515,7 +517,7 @@ impl Index {
515517

516518
if self.tracker_is_private().await {
517519
// Add main tracker URL
518-
match opt_user_id {
520+
match maybe_user_id {
519521
Some(user_id) => {
520522
let personal_announce_url = self.tracker_service.get_personal_announce_url(user_id).await?;
521523

@@ -568,10 +570,10 @@ impl Index {
568570
pub async fn get_canonical_info_hash(
569571
&self,
570572
info_hash: &InfoHash,
571-
opt_user_id: Option<UserId>,
573+
maybe_user_id: Option<UserId>,
572574
) -> Result<Option<InfoHash>, ServiceError> {
573575
self.authorization_service
574-
.authorize(ACTION::GetCanonicalInfoHash, opt_user_id)
576+
.authorize(ACTION::GetCanonicalInfoHash, maybe_user_id)
575577
.await?;
576578

577579
self.torrent_info_hash_repository

src/web/api/server/v1/contexts/about/handlers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use crate::web::api::server::v1::extractors::optional_user_id::ExtractOptionalLo
1212
#[allow(clippy::unused_async)]
1313
pub async fn about_page_handler(
1414
State(app_data): State<Arc<AppData>>,
15-
ExtractOptionalLoggedInUser(opt_user_id): ExtractOptionalLoggedInUser,
15+
ExtractOptionalLoggedInUser(maybe_user_id): ExtractOptionalLoggedInUser,
1616
) -> Response {
17-
match app_data.about_service.get_about_page(opt_user_id).await {
17+
match app_data.about_service.get_about_page(maybe_user_id).await {
1818
Ok(html) => (StatusCode::OK, [(header::CONTENT_TYPE, "text/html; charset=utf-8")], html).into_response(),
1919
Err(error) => error.into_response(),
2020
}
@@ -23,9 +23,9 @@ pub async fn about_page_handler(
2323
#[allow(clippy::unused_async)]
2424
pub async fn license_page_handler(
2525
State(app_data): State<Arc<AppData>>,
26-
ExtractOptionalLoggedInUser(opt_user_id): ExtractOptionalLoggedInUser,
26+
ExtractOptionalLoggedInUser(maybe_user_id): ExtractOptionalLoggedInUser,
2727
) -> Response {
28-
match app_data.about_service.get_license_page(opt_user_id).await {
28+
match app_data.about_service.get_license_page(maybe_user_id).await {
2929
Ok(html) => (StatusCode::OK, [(header::CONTENT_TYPE, "text/html; charset=utf-8")], html)
3030
.into_response()
3131
.into_response(),

src/web/api/server/v1/contexts/category/handlers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ use crate::web::api::server::v1::responses::{self};
2828
#[allow(clippy::unused_async)]
2929
pub async fn get_all_handler(
3030
State(app_data): State<Arc<AppData>>,
31-
ExtractOptionalLoggedInUser(opt_user_id): ExtractOptionalLoggedInUser,
31+
ExtractOptionalLoggedInUser(maybe_user_id): ExtractOptionalLoggedInUser,
3232
) -> Response {
33-
match app_data.category_service.get_categories(opt_user_id).await {
33+
match app_data.category_service.get_categories(maybe_user_id).await {
3434
Ok(categories) => {
3535
let categories: Vec<Category> = categories.into_iter().map(Category::from).collect();
3636
Json(responses::OkResponseData { data: categories }).into_response()

src/web/api/server/v1/contexts/proxy/handlers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::web::api::server::v1::extractors::optional_user_id::ExtractOptionalLo
1414
#[allow(clippy::unused_async)]
1515
pub async fn get_proxy_image_handler(
1616
State(app_data): State<Arc<AppData>>,
17-
ExtractOptionalLoggedInUser(opt_user_id): ExtractOptionalLoggedInUser,
17+
ExtractOptionalLoggedInUser(maybe_user_id): ExtractOptionalLoggedInUser,
1818
Path(url): Path<String>,
1919
) -> Response {
2020
// code-review: Handling status codes in the index-gui other tan OK is quite a pain.
@@ -27,7 +27,7 @@ pub async fn get_proxy_image_handler(
2727
// Get image URL from URL path parameter.
2828
let image_url = urlencoding::decode(&url).unwrap_or_default().into_owned();
2929

30-
match app_data.proxy_service.get_image_by_url(&image_url, opt_user_id).await {
30+
match app_data.proxy_service.get_image_by_url(&image_url, maybe_user_id).await {
3131
Ok(image_bytes) => {
3232
// Returns the cached image.
3333
png_image(image_bytes)

0 commit comments

Comments
 (0)