feat(gpodder): add signup link admin methods
This commit is contained in:
parent
c48d2a78ca
commit
5cd1f4f736
5 changed files with 102 additions and 2 deletions
|
|
@ -77,3 +77,9 @@ pub struct Page {
|
|||
pub struct UserFilter {
|
||||
pub username: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct SignupLink {
|
||||
pub id: i64,
|
||||
pub time_created: DateTime<Utc>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
use chrono::Utc;
|
||||
use rand::Rng;
|
||||
|
||||
use crate::{AuthErr, Page, models};
|
||||
|
||||
/// Admin view of the repository, providing methods only allowed by admins
|
||||
pub struct AdminRepository<'a> {
|
||||
pub(crate) store: &'a (dyn super::GpodderStore + Send + Sync),
|
||||
pub(crate) user: &'a models::User,
|
||||
pub(crate) _user: &'a models::User,
|
||||
}
|
||||
|
||||
impl<'a> AdminRepository<'a> {
|
||||
|
|
@ -14,4 +17,21 @@ impl<'a> AdminRepository<'a> {
|
|||
) -> Result<Vec<models::User>, AuthErr> {
|
||||
self.store.paginated_users(page, filter)
|
||||
}
|
||||
|
||||
/// Generate a new unique signup link ID
|
||||
pub fn generate_signup_link(&self) -> Result<models::SignupLink, AuthErr> {
|
||||
let link = models::SignupLink {
|
||||
id: rand::thread_rng().r#gen(),
|
||||
time_created: Utc::now(),
|
||||
};
|
||||
|
||||
self.store.insert_signup_link(&link)?;
|
||||
|
||||
Ok(link)
|
||||
}
|
||||
|
||||
/// Remove the signup link with the given ID, if it exists
|
||||
pub fn remove_signup_link(&self, id: i64) -> Result<bool, AuthErr> {
|
||||
self.store.remove_signup_link(id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ impl GpodderRepository {
|
|||
if user.admin {
|
||||
Ok(admin::AdminRepository {
|
||||
store: self.store.as_ref(),
|
||||
user,
|
||||
_user: user,
|
||||
})
|
||||
} else {
|
||||
Err(AuthErr::NotAnAdmin)
|
||||
|
|
|
|||
|
|
@ -67,6 +67,35 @@ pub trait GpodderAuthStore {
|
|||
|
||||
/// Return the given page of users, ordered by username
|
||||
fn paginated_users(&self, page: Page, filter: &UserFilter) -> Result<Vec<User>, AuthErr>;
|
||||
|
||||
/// Insert the signup link into the database.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// If a database failure occurs
|
||||
fn insert_signup_link(&self, link: &SignupLink) -> Result<(), AuthErr>;
|
||||
|
||||
/// Get the signup link associated with the given ID
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Some(link) if the ID corresponds to an existing signup link; None otherwise
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// If a database failure occurs
|
||||
fn get_signup_link(&self, id: i64) -> Result<Option<SignupLink>, AuthErr>;
|
||||
|
||||
/// Remove the signup link with the given ID.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// True if the ID existed in the database; false otherwise
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// If a database failure occurs
|
||||
fn remove_signup_link(&self, id: i64) -> Result<bool, AuthErr>;
|
||||
}
|
||||
|
||||
pub trait GpodderDeviceStore {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue