1
0
Fork 0
mirror of https://github.com/dani-garcia/vaultwarden.git synced 2025-09-08 02:32:41 +00:00

Merge pull request #1493 from jjlin/send

Add support for the Disable Send policy
This commit is contained in:
Daniel García 2021-03-16 18:13:55 +01:00 committed by GitHub
commit b987ba506d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 15 deletions

View file

@ -4,7 +4,7 @@ use crate::api::EmptyResult;
use crate::db::DbConn;
use crate::error::MapResult;
use super::{Organization, UserOrgStatus};
use super::{Organization, UserOrganization, UserOrgStatus, UserOrgType};
db_object! {
#[derive(Identifiable, Queryable, Insertable, Associations, AsChangeset)]
@ -20,7 +20,7 @@ db_object! {
}
}
#[allow(dead_code)]
#[derive(Copy, Clone)]
#[derive(num_derive::FromPrimitive)]
pub enum OrgPolicyType {
TwoFactorAuthentication = 0,
@ -29,6 +29,7 @@ pub enum OrgPolicyType {
// SingleOrg = 3, // Not currently supported.
// RequireSso = 4, // Not currently supported.
PersonalOwnership = 5,
DisableSend = 6,
}
/// Local methods
@ -170,6 +171,23 @@ impl OrgPolicy {
}}
}
/// Returns true if the user belongs to an org that has enabled the specified policy type,
/// and the user is not an owner or admin of that org. This is only useful for checking
/// applicability of policy types that have these particular semantics.
pub fn is_applicable_to_user(user_uuid: &str, policy_type: OrgPolicyType, conn: &DbConn) -> bool {
for policy in OrgPolicy::find_by_user(user_uuid, conn) { // Returns confirmed users only.
if policy.enabled && policy.has_type(policy_type) {
let org_uuid = &policy.org_uuid;
if let Some(user) = UserOrganization::find_by_user_and_org(user_uuid, org_uuid, conn) {
if user.atype < UserOrgType::Admin {
return true;
}
}
}
}
false
}
/*pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult {
db_run! { conn: {
diesel::delete(twofactor::table.filter(twofactor::user_uuid.eq(user_uuid)))