Skip to content

Commit 1ebaafc

Browse files
committed
require nda to become a curator
1 parent 0951ce3 commit 1ebaafc

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/db/operations/admins.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ pub async fn add_admin(
2121
profile: Profile,
2222
) -> Result<(), Error> {
2323
let group_name_f = group_name.to_owned();
24-
HOST_IS_GROUP_ADMIN.run(&RuleContext::minimal(
24+
CAN_ADD_CURATOR.run(&RuleContext::minimal_with_member_uuid(
2525
pool,
2626
scope_and_user,
2727
&group_name,
2828
&host.user_uuid,
29+
&user.user_uuid,
2930
))?;
3031
let connection = pool.get()?;
3132
internal::admin::add_admin(&connection, &group_name, host, user)?;

src/rules/engine.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub const SEARCH_USERS: Engine = Engine {
1616
};
1717

1818
pub const INVITE_MEMBER: Engine = Engine {
19-
rules: &[&rule_host_can_invite, &user_can_join, &user_not_a_member],
19+
rules: &[&rule_host_can_invite, &member_can_join, &user_not_a_member],
2020
};
2121

2222
pub const RENEW_MEMBER: Engine = Engine {
@@ -31,6 +31,10 @@ pub const EDIT_TERMS: Engine = Engine {
3131
rules: &[&rule_host_can_edit_terms],
3232
};
3333

34+
pub const CAN_ADD_CURATOR: Engine = Engine {
35+
rules: &[&rule_host_is_curator, &member_is_ndaed],
36+
};
37+
3438
pub const HOST_IS_CURATOR: Engine = Engine {
3539
rules: &[&rule_host_is_curator],
3640
};

src/rules/functions.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,22 @@ pub fn user_not_a_member(ctx: &RuleContext) -> Result<(), RuleError> {
7272
}
7373
}
7474

75+
/// Check if the member is nda'd
76+
pub fn member_is_ndaed(ctx: &RuleContext) -> Result<(), RuleError> {
77+
let connection = ctx.pool.get().map_err(|_| RuleError::PoolError)?;
78+
let trust = internal::user::user_trust(
79+
&connection,
80+
ctx.member_uuid.ok_or(RuleError::InvalidRuleContext)?,
81+
)
82+
.map_err(|_| RuleError::UserNotFound)?;
83+
if trust >= TrustType::Ndaed {
84+
return Ok(());
85+
}
86+
Err(RuleError::NotAllowedToJoinGroup)
87+
}
88+
7589
/// Check if the user is nda'd or the group is the nda group
76-
pub fn user_can_join(ctx: &RuleContext) -> Result<(), RuleError> {
90+
pub fn member_can_join(ctx: &RuleContext) -> Result<(), RuleError> {
7791
let connection = ctx.pool.get().map_err(|_| RuleError::PoolError)?;
7892
let trust = internal::user::user_trust(
7993
&connection,

0 commit comments

Comments
 (0)