Kontingente: sehen und nutzen getrennt; Admins rechnen eigene Keys nicht über fremde ab
- Actor::may_use_quota: zugeteilt oder selbst angelegt (System immer); may_see_quota: zusätzlich alles, was man verwaltet - QuotaInfo.usable; die Key-Auswahl zeigt nur nutzbare Kontingente Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
698249cb9b
commit
55116414e3
4 files changed
+31
-6
No files matched your search
@@ -246,6 +246,8 @@ pub struct QuotaInfo {
|
||||
pub owner: Option<String>,
|
||||
pub keys: usize,
|
||||
pub describe: String,
|
||||
/// Darf der Aufrufer eigene Keys darüber abrechnen (zugeteilt oder selbst angelegt)
|
||||
pub usable: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -686,7 +688,8 @@ impl<'a> Service<'a> {
|
||||
_ => None,
|
||||
};
|
||||
let keys = self.db.list_keys()?.iter().filter(|k| k.quota_id == Some(q.id) && !k.revoked).count();
|
||||
Ok(QuotaInfo { target, owner: self.username(q.owner_id)?, keys, describe: q.describe(), quota: q })
|
||||
let usable = self.actor.may_use_quota(&q, &self.my_groups()?);
|
||||
Ok(QuotaInfo { target, owner: self.username(q.owner_id)?, keys, describe: q.describe(), usable, quota: q })
|
||||
}
|
||||
|
||||
/// Kontingente, die der Handelnde verwaltet oder nutzen darf
|
||||
@@ -695,14 +698,14 @@ impl<'a> Service<'a> {
|
||||
self.db
|
||||
.list_quotas()?
|
||||
.into_iter()
|
||||
.filter(|q| self.actor.may_use_quota(q, &mine))
|
||||
.filter(|q| self.actor.may_see_quota(q, &mine))
|
||||
.map(|q| self.quota_info(q))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn show_quota(&self, id: i64) -> Result<QuotaDetail> {
|
||||
let q = self.quota(id)?;
|
||||
if !self.actor.may_use_quota(&q, &self.my_groups()?) {
|
||||
if !self.actor.may_see_quota(&q, &self.my_groups()?) {
|
||||
return Err(forbidden(format!("{} sieht das Kontingent {} nicht", self.who(), q.name)));
|
||||
}
|
||||
let now = Local::now();
|
||||
|
||||
Reference in new issue
Block a user