Skip to content

Commit

Permalink
filter member list according to permission matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Feb 17, 2020
1 parent 682f4d1 commit 6931222
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/db/internal/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::user::User;
use crate::utils::to_expiration_ts;
use chrono::NaiveDateTime;
use diesel::prelude::*;
use dino_park_trust::Trust;
use failure::Error;
use serde_json::Value;
use uuid::Uuid;
Expand All @@ -27,6 +28,7 @@ macro_rules! scoped_members_for {
roles: &[RoleType],
limit: i64,
offset: Option<i64>,
scope: &Trust,
) -> Result<PaginatedDisplayMembersAndHost, Error> {
use schema::groups as g;
use schema::memberships as m;
Expand Down Expand Up @@ -64,11 +66,17 @@ macro_rules! scoped_members_for {
u::email,
u::trust.eq(TrustType::Staff),
r::typ,
m::added_ts,
))
.offset(offset)
.limit(limit)
.get_results::<Member>(connection)
.map(|members| members.into_iter().map(|m| m.into()).collect())
.map(|members| {
members
.into_iter()
.map(|m| DisplayMemberAndHost::from_with_socpe(m, scope))
.collect()
})
})
.map(|members: Vec<DisplayMemberAndHost>| {
let next = match members.len() {
Expand Down Expand Up @@ -156,14 +164,14 @@ macro_rules! scoped_members_and_host_for {
}

// scoped_members_for!(users_staff, staff_scoped_members);
scoped_members_for!(users_ndaed, ndaed_scoped_members);
// scoped_members_for!(users_ndaed, ndaed_scoped_members);
scoped_members_for!(users_vouched, vouched_scoped_members);
scoped_members_for!(users_authenticated, authenticated_scoped_members);
scoped_members_for!(users_public, public_scoped_members);

scoped_members_and_host_for!(users_staff, hosts_staff, staff_scoped_members_and_host);
/*
scoped_members_and_host_for!(users_ndaed, hosts_ndaed, ndaed_scoped_members_and_host);
/*
scoped_members_and_host_for!(
users_vouched,
hosts_vouched,
Expand Down
5 changes: 4 additions & 1 deletion src/db/operations/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn scoped_members_and_host(
limit,
offset,
),
Trust::Ndaed => internal::member::ndaed_scoped_members(
Trust::Ndaed => internal::member::ndaed_scoped_members_and_host(
&connection,
group_name,
query,
Expand All @@ -62,6 +62,7 @@ pub fn scoped_members_and_host(
roles,
limit,
offset,
scope,
),
Trust::Authenticated => internal::member::authenticated_scoped_members(
&connection,
Expand All @@ -70,6 +71,7 @@ pub fn scoped_members_and_host(
roles,
limit,
offset,
scope,
),
Trust::Public => internal::member::public_scoped_members(
&connection,
Expand All @@ -78,6 +80,7 @@ pub fn scoped_members_and_host(
roles,
limit,
offset,
scope,
),
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/db/operations/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::db::model::Group;
use crate::db::model::GroupsList;
use crate::db::types::*;
use chrono::NaiveDateTime;
use dino_park_trust::Trust;
use serde_derive::Deserialize;
use serde_derive::Serialize;
use uuid::Uuid;
Expand Down Expand Up @@ -160,6 +161,7 @@ pub struct Member {
pub email: Option<String>,
pub is_staff: bool,
pub role: RoleType,
pub since: NaiveDateTime,
}

#[derive(Queryable, Serialize)]
Expand All @@ -181,8 +183,13 @@ pub struct MemberAndHost {
pub host_email: Option<String>,
}

impl From<Member> for DisplayMemberAndHost {
fn from(m: Member) -> Self {
impl DisplayMemberAndHost {
pub fn from_with_socpe(m: Member, scope: &Trust) -> Self {
let since = if scope >= &Trust::Authenticated {
Some(m.since)
} else {
None
};
DisplayMemberAndHost {
user_uuid: m.user_uuid,
picture: m.picture,
Expand All @@ -191,7 +198,7 @@ impl From<Member> for DisplayMemberAndHost {
username: m.username,
email: m.email,
is_staff: m.is_staff,
since: None,
since,
expiration: None,
role: m.role,
host: None,
Expand Down

0 comments on commit 6931222

Please sign in to comment.