mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-11 16:20:13 +00:00
feat(api): allow unauthed requests to /systems/:id/settings
This commit is contained in:
parent
0406c32f6b
commit
0610701252
14 changed files with 334 additions and 70 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use pluralkit_models::{PKSystem, PrivacyLevel, SystemId};
|
||||
|
||||
pub const INTERNAL_SYSTEMID_HEADER: &'static str = "x-pluralkit-systemid";
|
||||
pub const INTERNAL_APPID_HEADER: &'static str = "x-pluralkit-appid";
|
||||
|
||||
|
|
@ -19,4 +21,28 @@ impl AuthState {
|
|||
pub fn app_id(&self) -> Option<i32> {
|
||||
self.app_id
|
||||
}
|
||||
|
||||
pub fn access_level_for(&self, a: &impl Authable) -> PrivacyLevel {
|
||||
if self
|
||||
.system_id
|
||||
.map(|id| id == a.authable_system_id())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
PrivacyLevel::Private
|
||||
} else {
|
||||
PrivacyLevel::Public
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// authable trait/impls
|
||||
|
||||
pub trait Authable {
|
||||
fn authable_system_id(&self) -> SystemId;
|
||||
}
|
||||
|
||||
impl Authable for PKSystem {
|
||||
fn authable_system_id(&self) -> SystemId {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue