From 473f8b8e314b19faae1edae758b6716702bab6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Fri, 22 Feb 2019 20:25:50 +0100 Subject: [PATCH] remove some unneeded mutability --- src/api/admin.rs | 2 +- src/api/core/organizations.rs | 12 ++++++------ src/db/models/collection.rs | 4 ++-- src/db/models/organization.rs | 8 ++++---- src/db/models/user.rs | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/api/admin.rs b/src/api/admin.rs index 7f913640..d2e06b03 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -149,7 +149,7 @@ fn invite_user(data: Json, _token: AdminToken, conn: DbConn) -> Empt let org_name = "bitwarden_rs"; mail::send_invite(&user.email, &user.uuid, None, None, &org_name, None) } else { - let mut invitation = Invitation::new(data.email); + let invitation = Invitation::new(data.email); invitation.save(&conn) } } diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index bd2088c1..43967331 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -76,9 +76,9 @@ struct NewCollectionData { fn create_organization(headers: Headers, data: JsonUpcase, conn: DbConn) -> JsonResult { let data: OrgData = data.into_inner().data; - let mut org = Organization::new(data.Name, data.BillingEmail); + let org = Organization::new(data.Name, data.BillingEmail); let mut user_org = UserOrganization::new(headers.user.uuid.clone(), org.uuid.clone()); - let mut collection = Collection::new(org.uuid.clone(), data.CollectionName); + let collection = Collection::new(org.uuid.clone(), data.CollectionName); user_org.key = data.Key; user_org.access_all = true; @@ -221,7 +221,7 @@ fn post_organization_collections( None => err!("Can't find organization details"), }; - let mut collection = Collection::new(org.uuid.clone(), data.Name); + let collection = Collection::new(org.uuid.clone(), data.Name); collection.save(&conn)?; Ok(Json(collection.to_json())) @@ -484,7 +484,7 @@ fn send_invite(org_id: String, data: JsonUpcase, headers: AdminHeade } if !CONFIG.mail_enabled() { - let mut invitation = Invitation::new(email.clone()); + let invitation = Invitation::new(email.clone()); invitation.save(&conn)?; } @@ -581,7 +581,7 @@ fn reinvite_user(org_id: String, user_org: String, headers: AdminHeaders, conn: Some(headers.user.email), )?; } else { - let mut invitation = Invitation::new(user.email.clone()); + let invitation = Invitation::new(user.email.clone()); invitation.save(&conn)?; } @@ -851,7 +851,7 @@ fn post_org_import( .Collections .into_iter() .map(|coll| { - let mut collection = Collection::new(org_id.clone(), coll.Name); + let collection = Collection::new(org_id.clone(), coll.Name); if collection.save(&conn).is_err() { err!("Failed to create Collection"); } diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs index 5261bec4..c6047aa7 100644 --- a/src/db/models/collection.rs +++ b/src/db/models/collection.rs @@ -43,11 +43,11 @@ use crate::error::MapResult; /// Database methods impl Collection { - pub fn save(&mut self, conn: &DbConn) -> EmptyResult { + pub fn save(&self, conn: &DbConn) -> EmptyResult { self.update_users_revision(conn); diesel::replace_into(collections::table) - .values(&*self) + .values(self) .execute(&**conn) .map_res("Error saving collection") } diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index 702284cb..491c4fc3 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -213,7 +213,7 @@ use crate::error::MapResult; /// Database methods impl Organization { - pub fn save(&mut self, conn: &DbConn) -> EmptyResult { + pub fn save(&self, conn: &DbConn) -> EmptyResult { UserOrganization::find_by_org(&self.uuid, conn) .iter() .for_each(|user_org| { @@ -221,7 +221,7 @@ impl Organization { }); diesel::replace_into(organizations::table) - .values(&*self) + .values(self) .execute(&**conn) .map_res("Error saving organization") } @@ -323,11 +323,11 @@ impl UserOrganization { }) } - pub fn save(&mut self, conn: &DbConn) -> EmptyResult { + pub fn save(&self, conn: &DbConn) -> EmptyResult { User::update_uuid_revision(&self.user_uuid, conn); diesel::replace_into(users_organizations::table) - .values(&*self) + .values(self) .execute(&**conn) .map_res("Error adding user to organization") } diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 94ddc1ab..c447a922 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -225,13 +225,13 @@ impl Invitation { Self { email } } - pub fn save(&mut self, conn: &DbConn) -> EmptyResult { + pub fn save(&self, conn: &DbConn) -> EmptyResult { if self.email.trim().is_empty() { err!("Invitation email can't be empty") } diesel::replace_into(invitations::table) - .values(&*self) + .values(self) .execute(&**conn) .map_res("Error saving invitation") }