2021-03-31 22:18:35 +02:00
|
|
|
use num_traits::FromPrimitive;
|
2018-10-10 20:40:39 +02:00
|
|
|
use serde_json::Value;
|
2018-12-30 23:34:31 +01:00
|
|
|
use std::cmp::Ordering;
|
2018-04-24 22:01:55 +02:00
|
|
|
|
2021-03-31 22:18:35 +02:00
|
|
|
use super::{CollectionUser, OrgPolicy, User};
|
2018-04-24 22:01:55 +02:00
|
|
|
|
2020-08-18 17:15:44 +02:00
|
|
|
db_object! {
|
2021-03-13 22:04:04 +01:00
|
|
|
#[derive(Identifiable, Queryable, Insertable, AsChangeset)]
|
2020-08-18 17:15:44 +02:00
|
|
|
#[table_name = "organizations"]
|
|
|
|
#[primary_key(uuid)]
|
|
|
|
pub struct Organization {
|
|
|
|
pub uuid: String,
|
|
|
|
pub name: String,
|
|
|
|
pub billing_email: String,
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
pub private_key: Option<String>,
|
|
|
|
pub public_key: Option<String>,
|
2020-08-18 17:15:44 +02:00
|
|
|
}
|
|
|
|
|
2021-03-13 22:04:04 +01:00
|
|
|
#[derive(Identifiable, Queryable, Insertable, AsChangeset)]
|
2020-08-18 17:15:44 +02:00
|
|
|
#[table_name = "users_organizations"]
|
|
|
|
#[primary_key(uuid)]
|
|
|
|
pub struct UserOrganization {
|
|
|
|
pub uuid: String,
|
|
|
|
pub user_uuid: String,
|
|
|
|
pub org_uuid: String,
|
|
|
|
|
|
|
|
pub access_all: bool,
|
|
|
|
pub akey: String,
|
|
|
|
pub status: i32,
|
|
|
|
pub atype: i32,
|
|
|
|
}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub enum UserOrgStatus {
|
2018-09-10 15:51:40 +02:00
|
|
|
Invited = 0,
|
2018-04-24 22:01:55 +02:00
|
|
|
Accepted = 1,
|
|
|
|
Confirmed = 2,
|
|
|
|
}
|
|
|
|
|
2021-03-31 22:18:35 +02:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, num_derive::FromPrimitive)]
|
2018-04-24 22:01:55 +02:00
|
|
|
pub enum UserOrgType {
|
|
|
|
Owner = 0,
|
|
|
|
Admin = 1,
|
|
|
|
User = 2,
|
2018-11-12 18:13:25 +01:00
|
|
|
Manager = 3,
|
|
|
|
}
|
|
|
|
|
2020-09-13 11:03:16 +02:00
|
|
|
impl UserOrgType {
|
|
|
|
pub fn from_str(s: &str) -> Option<Self> {
|
|
|
|
match s {
|
|
|
|
"0" | "Owner" => Some(UserOrgType::Owner),
|
|
|
|
"1" | "Admin" => Some(UserOrgType::Admin),
|
|
|
|
"2" | "User" => Some(UserOrgType::User),
|
|
|
|
"3" | "Manager" => Some(UserOrgType::Manager),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 18:13:25 +01:00
|
|
|
impl Ord for UserOrgType {
|
|
|
|
fn cmp(&self, other: &UserOrgType) -> Ordering {
|
2020-09-13 11:03:16 +02:00
|
|
|
// For easy comparison, map each variant to an access level (where 0 is lowest).
|
|
|
|
static ACCESS_LEVEL: [i32; 4] = [
|
|
|
|
3, // Owner
|
|
|
|
2, // Admin
|
|
|
|
0, // User
|
|
|
|
1, // Manager
|
|
|
|
];
|
|
|
|
ACCESS_LEVEL[*self as usize].cmp(&ACCESS_LEVEL[*other as usize])
|
2018-11-12 18:13:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialOrd for UserOrgType {
|
|
|
|
fn partial_cmp(&self, other: &UserOrgType) -> Option<Ordering> {
|
|
|
|
Some(self.cmp(other))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq<i32> for UserOrgType {
|
|
|
|
fn eq(&self, other: &i32) -> bool {
|
|
|
|
*other == *self as i32
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialOrd<i32> for UserOrgType {
|
|
|
|
fn partial_cmp(&self, other: &i32) -> Option<Ordering> {
|
2018-12-07 15:01:29 +01:00
|
|
|
if let Some(other) = Self::from_i32(*other) {
|
2018-12-30 23:34:31 +01:00
|
|
|
return Some(self.cmp(&other));
|
2018-11-12 18:13:25 +01:00
|
|
|
}
|
2018-12-07 15:01:29 +01:00
|
|
|
None
|
2018-11-12 18:13:25 +01:00
|
|
|
}
|
2018-11-13 17:34:21 +01:00
|
|
|
|
|
|
|
fn gt(&self, other: &i32) -> bool {
|
2021-03-28 11:49:29 +02:00
|
|
|
matches!(self.partial_cmp(other), Some(Ordering::Greater))
|
2018-11-13 17:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ge(&self, other: &i32) -> bool {
|
2021-03-28 11:49:29 +02:00
|
|
|
matches!(self.partial_cmp(other), Some(Ordering::Greater) | Some(Ordering::Equal))
|
2018-11-13 17:34:21 +01:00
|
|
|
}
|
2018-11-12 18:13:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq<UserOrgType> for i32 {
|
|
|
|
fn eq(&self, other: &UserOrgType) -> bool {
|
|
|
|
*self == *other as i32
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialOrd<UserOrgType> for i32 {
|
|
|
|
fn partial_cmp(&self, other: &UserOrgType) -> Option<Ordering> {
|
2018-12-07 15:01:29 +01:00
|
|
|
if let Some(self_type) = UserOrgType::from_i32(*self) {
|
2018-12-30 23:34:31 +01:00
|
|
|
return Some(self_type.cmp(other));
|
2018-11-12 18:13:25 +01:00
|
|
|
}
|
2018-12-07 15:01:29 +01:00
|
|
|
None
|
2018-11-12 18:13:25 +01:00
|
|
|
}
|
2018-11-13 17:34:21 +01:00
|
|
|
|
|
|
|
fn lt(&self, other: &UserOrgType) -> bool {
|
2021-03-27 15:03:07 +01:00
|
|
|
matches!(self.partial_cmp(other), Some(Ordering::Less) | None)
|
2018-11-13 17:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn le(&self, other: &UserOrgType) -> bool {
|
2021-04-06 22:54:42 +02:00
|
|
|
matches!(self.partial_cmp(other), Some(Ordering::Less) | Some(Ordering::Equal) | None)
|
2018-11-13 17:34:21 +01:00
|
|
|
}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Local methods
|
|
|
|
impl Organization {
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
pub fn new(name: String, billing_email: String, private_key: Option<String>, public_key: Option<String>) -> Self {
|
2018-04-24 22:01:55 +02:00
|
|
|
Self {
|
2018-12-07 14:32:40 +01:00
|
|
|
uuid: crate::util::get_uuid(),
|
2018-04-24 22:01:55 +02:00
|
|
|
name,
|
|
|
|
billing_email,
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
private_key,
|
|
|
|
public_key,
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 20:40:39 +02:00
|
|
|
pub fn to_json(&self) -> Value {
|
2018-04-24 22:01:55 +02:00
|
|
|
json!({
|
|
|
|
"Id": self.uuid,
|
2021-01-31 21:46:37 +01:00
|
|
|
"Identifier": null, // not supported by us
|
2018-04-24 22:01:55 +02:00
|
|
|
"Name": self.name,
|
2021-01-31 21:46:37 +01:00
|
|
|
"Seats": 10, // The value doesn't matter, we don't check server-side
|
|
|
|
"MaxCollections": 10, // The value doesn't matter, we don't check server-side
|
2018-10-01 17:00:11 +02:00
|
|
|
"MaxStorageGb": 10, // The value doesn't matter, we don't check server-side
|
2018-07-01 15:49:16 +02:00
|
|
|
"Use2fa": true,
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
"UseDirectory": false, // Is supported, but this value isn't checked anywhere (yet)
|
|
|
|
"UseEvents": false, // not supported by us
|
|
|
|
"UseGroups": false, // not supported by us
|
2018-07-01 15:49:16 +02:00
|
|
|
"UseTotp": true,
|
2020-03-14 13:22:30 +01:00
|
|
|
"UsePolicies": true,
|
2021-01-31 21:46:37 +01:00
|
|
|
"UseSso": false, // We do not support SSO
|
|
|
|
"SelfHost": true,
|
|
|
|
"UseApi": false, // not supported by us
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
"HasPublicAndPrivateKeys": self.private_key.is_some() && self.public_key.is_some(),
|
|
|
|
"ResetPasswordEnrolled": false, // not supported by us
|
2018-04-24 22:01:55 +02:00
|
|
|
|
|
|
|
"BusinessName": null,
|
2020-05-08 00:02:37 +02:00
|
|
|
"BusinessAddress1": null,
|
|
|
|
"BusinessAddress2": null,
|
|
|
|
"BusinessAddress3": null,
|
2018-04-24 22:01:55 +02:00
|
|
|
"BusinessCountry": null,
|
|
|
|
"BusinessTaxNumber": null,
|
|
|
|
|
|
|
|
"BillingEmail": self.billing_email,
|
2018-07-01 15:49:16 +02:00
|
|
|
"Plan": "TeamsAnnually",
|
|
|
|
"PlanType": 5, // TeamsAnnually plan
|
2018-10-01 17:00:11 +02:00
|
|
|
"UsersGetPremium": true,
|
2018-04-24 22:01:55 +02:00
|
|
|
"Object": "organization",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UserOrganization {
|
|
|
|
pub fn new(user_uuid: String, org_uuid: String) -> Self {
|
|
|
|
Self {
|
2018-12-07 14:32:40 +01:00
|
|
|
uuid: crate::util::get_uuid(),
|
2018-04-24 22:01:55 +02:00
|
|
|
|
|
|
|
user_uuid,
|
|
|
|
org_uuid,
|
|
|
|
|
|
|
|
access_all: false,
|
2019-05-20 21:24:29 +02:00
|
|
|
akey: String::new(),
|
2018-04-24 22:01:55 +02:00
|
|
|
status: UserOrgStatus::Accepted as i32,
|
2019-05-20 21:12:41 +02:00
|
|
|
atype: UserOrgType::User as i32,
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 23:34:31 +01:00
|
|
|
use crate::db::DbConn;
|
2018-04-24 22:01:55 +02:00
|
|
|
|
2018-12-19 21:52:53 +01:00
|
|
|
use crate::api::EmptyResult;
|
|
|
|
use crate::error::MapResult;
|
|
|
|
|
2018-04-24 22:01:55 +02:00
|
|
|
/// Database methods
|
|
|
|
impl Organization {
|
2019-09-12 22:12:22 +02:00
|
|
|
pub fn save(&self, conn: &DbConn) -> EmptyResult {
|
2021-04-06 22:54:42 +02:00
|
|
|
UserOrganization::find_by_org(&self.uuid, conn).iter().for_each(|user_org| {
|
|
|
|
User::update_uuid_revision(&user_org.user_uuid, conn);
|
|
|
|
});
|
2019-09-12 22:12:22 +02:00
|
|
|
|
2020-09-22 12:13:02 +02:00
|
|
|
db_run! { conn:
|
2020-08-18 17:15:44 +02:00
|
|
|
sqlite, mysql {
|
2020-09-22 12:13:02 +02:00
|
|
|
match diesel::replace_into(organizations::table)
|
2020-08-18 17:15:44 +02:00
|
|
|
.values(OrganizationDb::to_db(self))
|
|
|
|
.execute(conn)
|
2020-09-22 12:13:02 +02:00
|
|
|
{
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
// Record already exists and causes a Foreign Key Violation because replace_into() wants to delete the record first.
|
|
|
|
Err(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::ForeignKeyViolation, _)) => {
|
|
|
|
diesel::update(organizations::table)
|
|
|
|
.filter(organizations::uuid.eq(&self.uuid))
|
|
|
|
.set(OrganizationDb::to_db(self))
|
|
|
|
.execute(conn)
|
|
|
|
.map_res("Error saving organization")
|
|
|
|
}
|
|
|
|
Err(e) => Err(e.into()),
|
|
|
|
}.map_res("Error saving organization")
|
|
|
|
|
2020-08-18 17:15:44 +02:00
|
|
|
}
|
|
|
|
postgresql {
|
|
|
|
let value = OrganizationDb::to_db(self);
|
|
|
|
diesel::insert_into(organizations::table)
|
|
|
|
.values(&value)
|
|
|
|
.on_conflict(organizations::uuid)
|
|
|
|
.do_update()
|
|
|
|
.set(&value)
|
|
|
|
.execute(conn)
|
2020-09-22 12:13:02 +02:00
|
|
|
.map_res("Error saving organization")
|
2020-08-18 17:15:44 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 21:52:53 +01:00
|
|
|
pub fn delete(self, conn: &DbConn) -> EmptyResult {
|
2018-05-18 17:52:51 +02:00
|
|
|
use super::{Cipher, Collection};
|
|
|
|
|
2021-06-19 22:02:03 +02:00
|
|
|
Cipher::delete_all_by_organization(&self.uuid, conn)?;
|
|
|
|
Collection::delete_all_by_organization(&self.uuid, conn)?;
|
|
|
|
UserOrganization::delete_all_by_organization(&self.uuid, conn)?;
|
|
|
|
OrgPolicy::delete_all_by_organization(&self.uuid, conn)?;
|
2018-05-18 17:52:51 +02:00
|
|
|
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
diesel::delete(organizations::table.filter(organizations::uuid.eq(self.uuid)))
|
|
|
|
.execute(conn)
|
|
|
|
.map_res("Error saving organization")
|
|
|
|
}}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn find_by_uuid(uuid: &str, conn: &DbConn) -> Option<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
organizations::table
|
|
|
|
.filter(organizations::uuid.eq(uuid))
|
|
|
|
.first::<OrganizationDb>(conn)
|
|
|
|
.ok().from_db()
|
|
|
|
}}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
2020-05-28 10:42:36 +02:00
|
|
|
|
|
|
|
pub fn get_all(conn: &DbConn) -> Vec<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
organizations::table.load::<OrganizationDb>(conn).expect("Error loading organizations").from_db()
|
|
|
|
}}
|
2020-05-28 10:42:36 +02:00
|
|
|
}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl UserOrganization {
|
2018-10-10 20:40:39 +02:00
|
|
|
pub fn to_json(&self, conn: &DbConn) -> Value {
|
2018-04-24 22:01:55 +02:00
|
|
|
let org = Organization::find_by_uuid(&self.org_uuid, conn).unwrap();
|
2020-09-22 12:13:02 +02:00
|
|
|
|
2018-04-24 22:01:55 +02:00
|
|
|
json!({
|
|
|
|
"Id": self.org_uuid,
|
2021-01-31 21:46:37 +01:00
|
|
|
"Identifier": null, // not supported by us
|
2018-04-24 22:01:55 +02:00
|
|
|
"Name": org.name,
|
2021-01-31 21:46:37 +01:00
|
|
|
"Seats": 10, // The value doesn't matter, we don't check server-side
|
|
|
|
"MaxCollections": 10, // The value doesn't matter, we don't check server-side
|
2018-10-01 17:00:11 +02:00
|
|
|
"UsersGetPremium": true,
|
2018-04-24 22:01:55 +02:00
|
|
|
|
2018-07-01 15:49:16 +02:00
|
|
|
"Use2fa": true,
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
"UseDirectory": false, // Is supported, but this value isn't checked anywhere (yet)
|
|
|
|
"UseEvents": false, // not supported by us
|
|
|
|
"UseGroups": false, // not supported by us
|
2018-07-01 15:49:16 +02:00
|
|
|
"UseTotp": true,
|
2020-03-14 13:22:30 +01:00
|
|
|
"UsePolicies": true,
|
2021-01-31 21:46:37 +01:00
|
|
|
"UseApi": false, // not supported by us
|
2020-05-08 19:39:17 +02:00
|
|
|
"SelfHost": true,
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
"HasPublicAndPrivateKeys": org.private_key.is_some() && org.public_key.is_some(),
|
|
|
|
"ResetPasswordEnrolled": false, // not supported by us
|
2021-01-31 21:46:37 +01:00
|
|
|
"SsoBound": false, // We do not support SSO
|
|
|
|
"UseSso": false, // We do not support SSO
|
|
|
|
// TODO: Add support for Business Portal
|
|
|
|
// Upstream is moving Policies and SSO management outside of the web-vault to /portal
|
|
|
|
// For now they still have that code also in the web-vault, but they will remove it at some point.
|
|
|
|
// https://github.com/bitwarden/server/tree/master/bitwarden_license/src/
|
|
|
|
"UseBusinessPortal": false, // Disable BusinessPortal Button
|
|
|
|
|
|
|
|
// TODO: Add support for Custom User Roles
|
|
|
|
// See: https://bitwarden.com/help/article/user-types-access-control/#custom-role
|
|
|
|
// "Permissions": {
|
|
|
|
// "AccessBusinessPortal": false,
|
|
|
|
// "AccessEventLogs": false,
|
|
|
|
// "AccessImportExport": false,
|
|
|
|
// "AccessReports": false,
|
|
|
|
// "ManageAllCollections": false,
|
|
|
|
// "ManageAssignedCollections": false,
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
// "ManageCiphers": false,
|
2021-01-31 21:46:37 +01:00
|
|
|
// "ManageGroups": false,
|
|
|
|
// "ManagePolicies": false,
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
// "ManageResetPassword": false,
|
2021-01-31 21:46:37 +01:00
|
|
|
// "ManageSso": false,
|
Added web-vault v2.21.x support + some misc fixes
- The new web-vault v2.21.0+ has support for Master Password Reset. For
this to work it generates a public/private key-pair which needs to be
stored in the database. Currently the Master Password Reset is not
fixed, but there are endpoints which are needed even if we do not
support this feature (yet). This PR fixes those endpoints, and stores
the keys already in the database.
- There was an issue when you want to do a key-rotate when you change
your password, it also called an Emergency Access endpoint, which we do
not yet support. Because this endpoint failed to reply correctly
produced some errors, and also prevent the user from being forced to
logout. This resolves #1826 by adding at least that endpoint.
Because of that extra endpoint check to Emergency Access is done using
an old user stamp, i also modified the stamp exception to allow multiple
rocket routes to be called, and added an expiration timestamp to it.
During these tests i stumbled upon an issue that after my key-change was
done, it triggered the websockets to try and reload my ciphers, because
they were updated. This shouldn't happen when rotating they keys, since
all access should be invalided. Now there will be no websocket
notification for this, which also prevents error toasts.
- Increased Send Size limit to 500MB (with a litle overhead)
As a side note, i tested these changes on both v2.20.4 and v2.21.1 web-vault versions, all keeps working.
2021-07-04 23:02:56 +02:00
|
|
|
// "ManageUsers": false,
|
2021-01-31 21:46:37 +01:00
|
|
|
// },
|
2018-04-24 22:01:55 +02:00
|
|
|
|
2018-06-01 00:50:22 +02:00
|
|
|
"MaxStorageGb": 10, // The value doesn't matter, we don't check server-side
|
2018-04-24 22:01:55 +02:00
|
|
|
|
|
|
|
// These are per user
|
2019-05-20 21:24:29 +02:00
|
|
|
"Key": self.akey,
|
2018-04-24 22:01:55 +02:00
|
|
|
"Status": self.status,
|
2019-05-20 21:12:41 +02:00
|
|
|
"Type": self.atype,
|
2018-04-24 22:01:55 +02:00
|
|
|
"Enabled": true,
|
|
|
|
|
|
|
|
"Object": "profileOrganization",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-10 20:40:39 +02:00
|
|
|
pub fn to_json_user_details(&self, conn: &DbConn) -> Value {
|
2018-04-24 22:01:55 +02:00
|
|
|
let user = User::find_by_uuid(&self.user_uuid, conn).unwrap();
|
|
|
|
|
|
|
|
json!({
|
|
|
|
"Id": self.uuid,
|
2018-04-25 00:34:40 +02:00
|
|
|
"UserId": self.user_uuid,
|
2018-04-24 22:01:55 +02:00
|
|
|
"Name": user.name,
|
|
|
|
"Email": user.email,
|
|
|
|
|
|
|
|
"Status": self.status,
|
2019-05-20 21:12:41 +02:00
|
|
|
"Type": self.atype,
|
2018-05-11 20:08:02 +02:00
|
|
|
"AccessAll": self.access_all,
|
2018-04-24 22:01:55 +02:00
|
|
|
|
|
|
|
"Object": "organizationUserUserDetails",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-03 06:51:20 +02:00
|
|
|
pub fn to_json_user_access_restrictions(&self, col_user: &CollectionUser) -> Value {
|
2018-05-29 17:01:38 +02:00
|
|
|
json!({
|
2019-01-25 15:18:06 +01:00
|
|
|
"Id": self.uuid,
|
2020-07-03 06:51:20 +02:00
|
|
|
"ReadOnly": col_user.read_only,
|
|
|
|
"HidePasswords": col_user.hide_passwords,
|
2018-05-29 17:01:38 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-12-30 23:34:31 +01:00
|
|
|
pub fn to_json_details(&self, conn: &DbConn) -> Value {
|
|
|
|
let coll_uuids = if self.access_all {
|
2018-05-11 20:08:02 +02:00
|
|
|
vec![] // If we have complete access, no need to fill the array
|
|
|
|
} else {
|
2018-05-17 00:05:50 +02:00
|
|
|
let collections = CollectionUser::find_by_organization_and_user_uuid(&self.org_uuid, &self.user_uuid, conn);
|
2018-12-30 23:34:31 +01:00
|
|
|
collections
|
|
|
|
.iter()
|
2021-03-31 22:18:35 +02:00
|
|
|
.map(|c| {
|
|
|
|
json!({
|
|
|
|
"Id": c.collection_uuid,
|
|
|
|
"ReadOnly": c.read_only,
|
|
|
|
"HidePasswords": c.hide_passwords,
|
|
|
|
})
|
|
|
|
})
|
2018-12-30 23:34:31 +01:00
|
|
|
.collect()
|
2018-05-11 20:08:02 +02:00
|
|
|
};
|
|
|
|
|
2018-04-25 00:34:40 +02:00
|
|
|
json!({
|
|
|
|
"Id": self.uuid,
|
|
|
|
"UserId": self.user_uuid,
|
|
|
|
|
|
|
|
"Status": self.status,
|
2019-05-20 21:12:41 +02:00
|
|
|
"Type": self.atype,
|
2018-05-11 20:08:02 +02:00
|
|
|
"AccessAll": self.access_all,
|
|
|
|
"Collections": coll_uuids,
|
2018-04-25 00:34:40 +02:00
|
|
|
|
|
|
|
"Object": "organizationUserDetails",
|
|
|
|
})
|
|
|
|
}
|
2019-09-12 22:12:22 +02:00
|
|
|
pub fn save(&self, conn: &DbConn) -> EmptyResult {
|
|
|
|
User::update_uuid_revision(&self.user_uuid, conn);
|
|
|
|
|
2020-09-22 12:13:02 +02:00
|
|
|
db_run! { conn:
|
2020-08-18 17:15:44 +02:00
|
|
|
sqlite, mysql {
|
2020-09-22 12:13:02 +02:00
|
|
|
match diesel::replace_into(users_organizations::table)
|
2020-08-18 17:15:44 +02:00
|
|
|
.values(UserOrganizationDb::to_db(self))
|
|
|
|
.execute(conn)
|
2020-09-22 12:13:02 +02:00
|
|
|
{
|
|
|
|
Ok(_) => Ok(()),
|
|
|
|
// Record already exists and causes a Foreign Key Violation because replace_into() wants to delete the record first.
|
|
|
|
Err(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::ForeignKeyViolation, _)) => {
|
|
|
|
diesel::update(users_organizations::table)
|
|
|
|
.filter(users_organizations::uuid.eq(&self.uuid))
|
|
|
|
.set(UserOrganizationDb::to_db(self))
|
|
|
|
.execute(conn)
|
|
|
|
.map_res("Error adding user to organization")
|
|
|
|
}
|
|
|
|
Err(e) => Err(e.into()),
|
|
|
|
}.map_res("Error adding user to organization")
|
2020-08-18 17:15:44 +02:00
|
|
|
}
|
|
|
|
postgresql {
|
|
|
|
let value = UserOrganizationDb::to_db(self);
|
|
|
|
diesel::insert_into(users_organizations::table)
|
|
|
|
.values(&value)
|
|
|
|
.on_conflict(users_organizations::uuid)
|
|
|
|
.do_update()
|
|
|
|
.set(&value)
|
|
|
|
.execute(conn)
|
2020-09-22 12:13:02 +02:00
|
|
|
.map_res("Error adding user to organization")
|
2020-08-18 17:15:44 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 21:52:53 +01:00
|
|
|
pub fn delete(self, conn: &DbConn) -> EmptyResult {
|
2018-08-21 14:26:22 +02:00
|
|
|
User::update_uuid_revision(&self.user_uuid, conn);
|
2018-05-18 17:52:51 +02:00
|
|
|
|
2021-06-19 22:02:03 +02:00
|
|
|
CollectionUser::delete_all_by_user_and_org(&self.user_uuid, &self.org_uuid, conn)?;
|
2018-05-18 17:52:51 +02:00
|
|
|
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
diesel::delete(users_organizations::table.filter(users_organizations::uuid.eq(self.uuid)))
|
|
|
|
.execute(conn)
|
|
|
|
.map_res("Error removing user from organization")
|
|
|
|
}}
|
2018-05-18 17:52:51 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 21:52:53 +01:00
|
|
|
pub fn delete_all_by_organization(org_uuid: &str, conn: &DbConn) -> EmptyResult {
|
2021-06-19 22:02:03 +02:00
|
|
|
for user_org in Self::find_by_org(org_uuid, conn) {
|
|
|
|
user_org.delete(conn)?;
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
2018-05-18 17:52:51 +02:00
|
|
|
Ok(())
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
|
2018-12-19 21:52:53 +01:00
|
|
|
pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult {
|
2021-06-19 22:02:03 +02:00
|
|
|
for user_org in Self::find_any_state_by_user(user_uuid, conn) {
|
|
|
|
user_org.delete(conn)?;
|
2018-10-12 16:20:10 +02:00
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-02-06 18:22:39 +01:00
|
|
|
pub fn find_by_email_and_org(email: &str, org_id: &str, conn: &DbConn) -> Option<UserOrganization> {
|
|
|
|
if let Some(user) = super::User::find_by_mail(email, conn) {
|
2021-06-19 22:02:03 +02:00
|
|
|
if let Some(user_org) = UserOrganization::find_by_user_and_org(&user.uuid, org_id, conn) {
|
2021-02-06 18:22:39 +01:00
|
|
|
return Some(user_org);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2021-01-24 05:50:06 +01:00
|
|
|
pub fn has_status(&self, status: UserOrgStatus) -> bool {
|
2020-07-03 19:49:10 +02:00
|
|
|
self.status == status as i32
|
|
|
|
}
|
|
|
|
|
2021-01-24 05:50:06 +01:00
|
|
|
pub fn has_type(&self, user_type: UserOrgType) -> bool {
|
|
|
|
self.atype == user_type as i32
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_full_access(&self) -> bool {
|
2021-03-31 22:18:35 +02:00
|
|
|
(self.access_all || self.atype >= UserOrgType::Admin) && self.has_status(UserOrgStatus::Confirmed)
|
2018-05-14 17:13:59 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 00:34:40 +02:00
|
|
|
pub fn find_by_uuid(uuid: &str, conn: &DbConn) -> Option<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::uuid.eq(uuid))
|
|
|
|
.first::<UserOrganizationDb>(conn)
|
|
|
|
.ok().from_db()
|
|
|
|
}}
|
2018-04-25 00:34:40 +02:00
|
|
|
}
|
|
|
|
|
2018-09-04 12:24:53 +02:00
|
|
|
pub fn find_by_uuid_and_org(uuid: &str, org_uuid: &str, conn: &DbConn) -> Option<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::uuid.eq(uuid))
|
|
|
|
.filter(users_organizations::org_uuid.eq(org_uuid))
|
|
|
|
.first::<UserOrganizationDb>(conn)
|
|
|
|
.ok().from_db()
|
|
|
|
}}
|
2018-09-04 12:24:53 +02:00
|
|
|
}
|
|
|
|
|
2018-05-03 18:47:27 +02:00
|
|
|
pub fn find_by_user(user_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::user_uuid.eq(user_uuid))
|
|
|
|
.filter(users_organizations::status.eq(UserOrgStatus::Confirmed as i32))
|
|
|
|
.load::<UserOrganizationDb>(conn)
|
|
|
|
.unwrap_or_default().from_db()
|
|
|
|
}}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
|
2018-09-10 15:51:40 +02:00
|
|
|
pub fn find_invited_by_user(user_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::user_uuid.eq(user_uuid))
|
|
|
|
.filter(users_organizations::status.eq(UserOrgStatus::Invited as i32))
|
|
|
|
.load::<UserOrganizationDb>(conn)
|
|
|
|
.unwrap_or_default().from_db()
|
|
|
|
}}
|
2018-09-10 15:51:40 +02:00
|
|
|
}
|
|
|
|
|
2018-10-12 16:20:10 +02:00
|
|
|
pub fn find_any_state_by_user(user_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::user_uuid.eq(user_uuid))
|
|
|
|
.load::<UserOrganizationDb>(conn)
|
|
|
|
.unwrap_or_default().from_db()
|
|
|
|
}}
|
2018-10-12 16:20:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn find_by_org(org_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::org_uuid.eq(org_uuid))
|
|
|
|
.load::<UserOrganizationDb>(conn)
|
|
|
|
.expect("Error loading user organizations").from_db()
|
|
|
|
}}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
|
|
|
|
2020-06-03 20:37:31 +02:00
|
|
|
pub fn count_by_org(org_uuid: &str, conn: &DbConn) -> i64 {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::org_uuid.eq(org_uuid))
|
|
|
|
.count()
|
|
|
|
.first::<i64>(conn)
|
|
|
|
.ok()
|
|
|
|
.unwrap_or(0)
|
|
|
|
}}
|
2020-06-03 20:37:31 +02:00
|
|
|
}
|
|
|
|
|
2019-05-20 21:12:41 +02:00
|
|
|
pub fn find_by_org_and_type(org_uuid: &str, atype: i32, conn: &DbConn) -> Vec<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::org_uuid.eq(org_uuid))
|
|
|
|
.filter(users_organizations::atype.eq(atype))
|
|
|
|
.load::<UserOrganizationDb>(conn)
|
|
|
|
.expect("Error loading user organizations").from_db()
|
|
|
|
}}
|
2018-04-25 00:34:40 +02:00
|
|
|
}
|
|
|
|
|
2018-04-24 22:01:55 +02:00
|
|
|
pub fn find_by_user_and_org(user_uuid: &str, org_uuid: &str, conn: &DbConn) -> Option<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::user_uuid.eq(user_uuid))
|
|
|
|
.filter(users_organizations::org_uuid.eq(org_uuid))
|
|
|
|
.first::<UserOrganizationDb>(conn)
|
|
|
|
.ok().from_db()
|
|
|
|
}}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
2018-08-21 18:31:01 +02:00
|
|
|
|
|
|
|
pub fn find_by_cipher_and_org(cipher_uuid: &str, org_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::org_uuid.eq(org_uuid))
|
|
|
|
.left_join(users_collections::table.on(
|
|
|
|
users_collections::user_uuid.eq(users_organizations::user_uuid)
|
|
|
|
))
|
|
|
|
.left_join(ciphers_collections::table.on(
|
|
|
|
ciphers_collections::collection_uuid.eq(users_collections::collection_uuid).and(
|
|
|
|
ciphers_collections::cipher_uuid.eq(&cipher_uuid)
|
|
|
|
)
|
|
|
|
))
|
|
|
|
.filter(
|
|
|
|
users_organizations::access_all.eq(true).or( // AccessAll..
|
|
|
|
ciphers_collections::cipher_uuid.eq(&cipher_uuid) // ..or access to collection with cipher
|
|
|
|
)
|
2018-08-21 18:31:01 +02:00
|
|
|
)
|
2020-08-18 17:15:44 +02:00
|
|
|
.select(users_organizations::all_columns)
|
|
|
|
.load::<UserOrganizationDb>(conn).expect("Error loading user organizations").from_db()
|
|
|
|
}}
|
2018-08-21 18:31:01 +02:00
|
|
|
}
|
2018-10-01 17:52:36 +02:00
|
|
|
|
|
|
|
pub fn find_by_collection_and_org(collection_uuid: &str, org_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
2020-08-18 17:15:44 +02:00
|
|
|
db_run! { conn: {
|
|
|
|
users_organizations::table
|
|
|
|
.filter(users_organizations::org_uuid.eq(org_uuid))
|
|
|
|
.left_join(users_collections::table.on(
|
|
|
|
users_collections::user_uuid.eq(users_organizations::user_uuid)
|
|
|
|
))
|
|
|
|
.filter(
|
|
|
|
users_organizations::access_all.eq(true).or( // AccessAll..
|
|
|
|
users_collections::collection_uuid.eq(&collection_uuid) // ..or access to collection with cipher
|
|
|
|
)
|
2018-10-01 17:52:36 +02:00
|
|
|
)
|
2020-08-18 17:15:44 +02:00
|
|
|
.select(users_organizations::all_columns)
|
|
|
|
.load::<UserOrganizationDb>(conn).expect("Error loading user organizations").from_db()
|
|
|
|
}}
|
2018-10-01 17:52:36 +02:00
|
|
|
}
|
2018-04-24 22:01:55 +02:00
|
|
|
}
|
2020-09-13 11:03:16 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
fn partial_cmp_UserOrgType() {
|
|
|
|
assert!(UserOrgType::Owner > UserOrgType::Admin);
|
|
|
|
assert!(UserOrgType::Admin > UserOrgType::Manager);
|
|
|
|
assert!(UserOrgType::Manager > UserOrgType::User);
|
|
|
|
}
|
|
|
|
}
|