-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform): make subscription management and feature overview URL…
…s configurable
- Loading branch information
Showing
7 changed files
with
146 additions
and
20 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use url::Url; | ||
|
||
/// Configuration related to the Secutils.dev subscriptions. | ||
#[derive(Clone, Debug)] | ||
pub struct SubscriptionsConfig { | ||
/// The URL to access the subscription management page. | ||
pub manage_url: Option<Url>, | ||
/// The URL to access the feature overview page. | ||
pub feature_overview_url: Option<Url>, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::users::SubscriptionFeatures; | ||
use serde_derive::Serialize; | ||
use url::Url; | ||
|
||
/// Defines subscription related properties returned as a part of the UI state. | ||
#[derive(Clone, Serialize, Default, PartialEq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct SubscriptionState<'u> { | ||
/// The subscription-dependent features available to the user. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub features: Option<SubscriptionFeatures>, | ||
/// The URL to the subscription management page. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub manage_url: Option<&'u Url>, | ||
/// The URL to the subscription overview page. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub feature_overview_url: Option<&'u Url>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::{ | ||
server::SubscriptionState, | ||
tests::{mock_config, mock_user}, | ||
}; | ||
use insta::assert_json_snapshot; | ||
use url::Url; | ||
|
||
#[test] | ||
fn serialization() -> anyhow::Result<()> { | ||
assert_json_snapshot!(SubscriptionState::default(), @"{}"); | ||
|
||
let user = mock_user()?; | ||
let features = user.subscription.get_features(&mock_config()?); | ||
let manage_url = Url::parse("http:https://localhost:1234/subscription")?; | ||
let feature_overview_url = Url::parse("http:https://localhost:1234/features")?; | ||
|
||
assert_json_snapshot!(SubscriptionState { | ||
features: Some(features), | ||
manage_url: Some(&manage_url), | ||
feature_overview_url: Some(&feature_overview_url), | ||
}, @r###" | ||
{ | ||
"features": { | ||
"admin": true | ||
}, | ||
"manageUrl": "http:https://localhost:1234/subscription", | ||
"featureOverviewUrl": "http:https://localhost:1234/features" | ||
} | ||
"###); | ||
|
||
Ok(()) | ||
} | ||
} |