|
|
@ -160,24 +160,16 @@ impl Group { |
|
|
self.revision_date = Utc::now().naive_utc(); |
|
|
self.revision_date = Utc::now().naive_utc(); |
|
|
|
|
|
|
|
|
db_run! { conn: |
|
|
db_run! { conn: |
|
|
sqlite, mysql { |
|
|
mysql { |
|
|
match diesel::replace_into(groups::table) |
|
|
diesel::insert_into(groups::table) |
|
|
.values(&*self) |
|
|
.values(&*self) |
|
|
.execute(conn) |
|
|
.on_conflict(diesel::dsl::DuplicatedKeys) |
|
|
{ |
|
|
.do_update() |
|
|
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(groups::table) |
|
|
|
|
|
.filter(groups::uuid.eq(&self.uuid)) |
|
|
|
|
|
.set(&*self) |
|
|
.set(&*self) |
|
|
.execute(conn) |
|
|
.execute(conn) |
|
|
.map_res("Error saving group") |
|
|
.map_res("Error saving group") |
|
|
} |
|
|
} |
|
|
Err(e) => Err(e.into()), |
|
|
postgresql, sqlite { |
|
|
}.map_res("Error saving group") |
|
|
|
|
|
} |
|
|
|
|
|
postgresql { |
|
|
|
|
|
diesel::insert_into(groups::table) |
|
|
diesel::insert_into(groups::table) |
|
|
.values(&*self) |
|
|
.values(&*self) |
|
|
.on_conflict(groups::uuid) |
|
|
.on_conflict(groups::uuid) |
|
|
@ -312,53 +304,30 @@ impl CollectionGroup { |
|
|
group_user.update_user_revision(conn).await; |
|
|
group_user.update_user_revision(conn).await; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
db_run! { conn: |
|
|
let values = ( |
|
|
sqlite, mysql { |
|
|
|
|
|
match diesel::replace_into(collections_groups::table) |
|
|
|
|
|
.values(( |
|
|
|
|
|
collections_groups::collections_uuid.eq(&self.collections_uuid), |
|
|
collections_groups::collections_uuid.eq(&self.collections_uuid), |
|
|
collections_groups::groups_uuid.eq(&self.groups_uuid), |
|
|
collections_groups::groups_uuid.eq(&self.groups_uuid), |
|
|
collections_groups::read_only.eq(&self.read_only), |
|
|
collections_groups::read_only.eq(&self.read_only), |
|
|
collections_groups::hide_passwords.eq(&self.hide_passwords), |
|
|
collections_groups::hide_passwords.eq(&self.hide_passwords), |
|
|
collections_groups::manage.eq(&self.manage), |
|
|
collections_groups::manage.eq(&self.manage), |
|
|
)) |
|
|
); |
|
|
.execute(conn) |
|
|
|
|
|
{ |
|
|
db_run! { conn: |
|
|
Ok(_) => Ok(()), |
|
|
mysql { |
|
|
// Record already exists and causes a Foreign Key Violation because replace_into() wants to delete the record first.
|
|
|
diesel::insert_into(collections_groups::table) |
|
|
Err(diesel::result::Error::DatabaseError(diesel::result::DatabaseErrorKind::ForeignKeyViolation, _)) => { |
|
|
.values(values) |
|
|
diesel::update(collections_groups::table) |
|
|
.on_conflict(diesel::dsl::DuplicatedKeys) |
|
|
.filter(collections_groups::collections_uuid.eq(&self.collections_uuid)) |
|
|
.do_update() |
|
|
.filter(collections_groups::groups_uuid.eq(&self.groups_uuid)) |
|
|
.set(values) |
|
|
.set(( |
|
|
|
|
|
collections_groups::collections_uuid.eq(&self.collections_uuid), |
|
|
|
|
|
collections_groups::groups_uuid.eq(&self.groups_uuid), |
|
|
|
|
|
collections_groups::read_only.eq(&self.read_only), |
|
|
|
|
|
collections_groups::hide_passwords.eq(&self.hide_passwords), |
|
|
|
|
|
collections_groups::manage.eq(&self.manage), |
|
|
|
|
|
)) |
|
|
|
|
|
.execute(conn) |
|
|
.execute(conn) |
|
|
.map_res("Error adding group to collection") |
|
|
.map_res("Error adding group to collection") |
|
|
} |
|
|
} |
|
|
Err(e) => Err(e.into()), |
|
|
postgresql, sqlite { |
|
|
}.map_res("Error adding group to collection") |
|
|
|
|
|
} |
|
|
|
|
|
postgresql { |
|
|
|
|
|
diesel::insert_into(collections_groups::table) |
|
|
diesel::insert_into(collections_groups::table) |
|
|
.values(( |
|
|
.values(values) |
|
|
collections_groups::collections_uuid.eq(&self.collections_uuid), |
|
|
|
|
|
collections_groups::groups_uuid.eq(&self.groups_uuid), |
|
|
|
|
|
collections_groups::read_only.eq(self.read_only), |
|
|
|
|
|
collections_groups::hide_passwords.eq(self.hide_passwords), |
|
|
|
|
|
collections_groups::manage.eq(self.manage), |
|
|
|
|
|
)) |
|
|
|
|
|
.on_conflict((collections_groups::collections_uuid, collections_groups::groups_uuid)) |
|
|
.on_conflict((collections_groups::collections_uuid, collections_groups::groups_uuid)) |
|
|
.do_update() |
|
|
.do_update() |
|
|
.set(( |
|
|
.set(values) |
|
|
collections_groups::read_only.eq(self.read_only), |
|
|
|
|
|
collections_groups::hide_passwords.eq(self.hide_passwords), |
|
|
|
|
|
collections_groups::manage.eq(self.manage), |
|
|
|
|
|
)) |
|
|
|
|
|
.execute(conn) |
|
|
.execute(conn) |
|
|
.map_res("Error adding group to collection") |
|
|
.map_res("Error adding group to collection") |
|
|
} |
|
|
} |
|
|
@ -451,43 +420,25 @@ impl GroupUser { |
|
|
pub async fn save(&mut self, conn: &DbConn) -> EmptyResult { |
|
|
pub async fn save(&mut self, conn: &DbConn) -> EmptyResult { |
|
|
self.update_user_revision(conn).await; |
|
|
self.update_user_revision(conn).await; |
|
|
|
|
|
|
|
|
db_run! { conn: |
|
|
let values = ( |
|
|
sqlite, mysql { |
|
|
|
|
|
match diesel::replace_into(groups_users::table) |
|
|
|
|
|
.values(( |
|
|
|
|
|
groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid), |
|
|
|
|
|
groups_users::groups_uuid.eq(&self.groups_uuid), |
|
|
|
|
|
)) |
|
|
|
|
|
.execute(conn) |
|
|
|
|
|
{ |
|
|
|
|
|
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(groups_users::table) |
|
|
|
|
|
.filter(groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid)) |
|
|
|
|
|
.filter(groups_users::groups_uuid.eq(&self.groups_uuid)) |
|
|
|
|
|
.set(( |
|
|
|
|
|
groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid), |
|
|
groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid), |
|
|
groups_users::groups_uuid.eq(&self.groups_uuid), |
|
|
groups_users::groups_uuid.eq(&self.groups_uuid), |
|
|
)) |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
db_run! { conn: |
|
|
|
|
|
mysql { |
|
|
|
|
|
diesel::insert_into(groups_users::table) |
|
|
|
|
|
.values(values) |
|
|
|
|
|
.on_conflict(diesel::dsl::DuplicatedKeys) |
|
|
|
|
|
.do_nothing() |
|
|
.execute(conn) |
|
|
.execute(conn) |
|
|
.map_res("Error adding user to group") |
|
|
.map_res("Error adding user to group") |
|
|
} |
|
|
} |
|
|
Err(e) => Err(e.into()), |
|
|
postgresql, sqlite { |
|
|
}.map_res("Error adding user to group") |
|
|
|
|
|
} |
|
|
|
|
|
postgresql { |
|
|
|
|
|
diesel::insert_into(groups_users::table) |
|
|
diesel::insert_into(groups_users::table) |
|
|
.values(( |
|
|
.values(values) |
|
|
groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid), |
|
|
|
|
|
groups_users::groups_uuid.eq(&self.groups_uuid), |
|
|
|
|
|
)) |
|
|
|
|
|
.on_conflict((groups_users::users_organizations_uuid, groups_users::groups_uuid)) |
|
|
.on_conflict((groups_users::users_organizations_uuid, groups_users::groups_uuid)) |
|
|
.do_update() |
|
|
.do_nothing() |
|
|
.set(( |
|
|
|
|
|
groups_users::users_organizations_uuid.eq(&self.users_organizations_uuid), |
|
|
|
|
|
groups_users::groups_uuid.eq(&self.groups_uuid), |
|
|
|
|
|
)) |
|
|
|
|
|
.execute(conn) |
|
|
.execute(conn) |
|
|
.map_res("Error adding user to group") |
|
|
.map_res("Error adding user to group") |
|
|
} |
|
|
} |
|
|
|