@@ -20,7 +20,7 @@ use crate::{
2020 util:: { LowerCase , NumberOrString , format_date} ,
2121} ;
2222
23- use super :: { OrganizationId , User , UserId } ;
23+ use super :: { User , UserId } ;
2424
2525#[ derive( Identifiable , Queryable , Insertable , AsChangeset , Selectable ) ]
2626#[ diesel( table_name = sends) ]
@@ -29,8 +29,7 @@ use super::{OrganizationId, User, UserId};
2929pub struct Send {
3030 pub uuid : SendId ,
3131
32- pub user_uuid : Option < UserId > ,
33- pub organization_uuid : Option < OrganizationId > ,
32+ pub user_uuid : UserId ,
3433
3534 pub name : String ,
3635 pub notes : Option < String > ,
@@ -52,7 +51,7 @@ pub struct Send {
5251 pub deletion_date : NaiveDateTime ,
5352
5453 pub disabled : bool ,
55- pub hide_email : Option < bool > ,
54+ pub hide_email : bool ,
5655}
5756
5857#[ derive( Copy , Clone , PartialEq , Eq , num_derive:: FromPrimitive ) ]
@@ -85,14 +84,13 @@ impl Send {
8584 expiration_date : Option < NaiveDateTime > ,
8685 deletion_date : NaiveDateTime ,
8786 disabled : bool ,
88- hide_email : Option < bool > ,
87+ hide_email : bool ,
8988 ) -> Self {
9089 let now = Utc :: now ( ) . naive_utc ( ) ;
9190
9291 Self {
9392 uuid : SendId :: from ( crate :: util:: get_uuid ( ) ) ,
94- user_uuid : Some ( user_uuid) ,
95- organization_uuid : None ,
93+ user_uuid,
9694 name,
9795 notes,
9896 atype,
@@ -142,19 +140,13 @@ impl Send {
142140 }
143141
144142 pub async fn creator_identifier ( & self , conn : & DbConn ) -> Option < String > {
145- if let Some ( hide_email ) = self . hide_email
146- && hide_email
143+ if ! self . hide_email
144+ && let Some ( user ) = User :: find_by_uuid ( & self . user_uuid , conn ) . await
147145 {
148- return None ;
149- }
150-
151- if let Some ( user_uuid) = & self . user_uuid
152- && let Some ( user) = User :: find_by_uuid ( user_uuid, conn) . await
153- {
154- return Some ( user. email ) ;
146+ Some ( user. email )
147+ } else {
148+ None
155149 }
156-
157- None
158150 }
159151
160152 pub fn to_json ( & self ) -> Value {
@@ -181,7 +173,7 @@ impl Send {
181173 "password" : self . password_hash. as_deref( ) . map( |h| BASE64URL_NOPAD . encode( h) ) ,
182174 "authType" : if self . password_hash. is_some( ) { SendAuthType :: Password } else if self . emails. is_some( ) { SendAuthType :: Email } else { SendAuthType :: None } as i32 ,
183175 "disabled" : self . disabled,
184- "hideEmail" : self . hide_email. unwrap_or ( false ) ,
176+ "hideEmail" : self . hide_email,
185177 "emails" : self . emails,
186178
187179 "revisionDate" : format_date( & self . revision_date) ,
@@ -263,14 +255,8 @@ impl Send {
263255 }
264256
265257 pub async fn update_users_revision ( & self , conn : & DbConn ) -> Vec < UserId > {
266- let mut user_uuids = Vec :: new ( ) ;
267- if let Some ( user_uuid) = & self . user_uuid {
268- User :: update_uuid_revision ( user_uuid, conn) . await ;
269- user_uuids. push ( user_uuid. clone ( ) ) ;
270- } else {
271- // Belongs to Organization, not implemented
272- }
273- user_uuids
258+ User :: update_uuid_revision ( & self . user_uuid , conn) . await ;
259+ vec ! [ self . user_uuid. clone( ) ]
274260 }
275261
276262 pub async fn delete_all_by_user ( user_uuid : & UserId , conn : & DbConn ) -> EmptyResult {
@@ -332,13 +318,6 @@ impl Send {
332318 Some ( total)
333319 }
334320
335- pub async fn find_by_org ( org_uuid : & OrganizationId , conn : & DbConn ) -> Vec < Self > {
336- conn. run ( move |conn| {
337- sends:: table. filter ( sends:: organization_uuid. eq ( org_uuid) ) . load :: < Self > ( conn) . expect ( "Error loading sends" )
338- } )
339- . await
340- }
341-
342321 pub async fn find_by_past_deletion_date ( conn : & DbConn ) -> Vec < Self > {
343322 let now = Utc :: now ( ) . naive_utc ( ) ;
344323 conn. run ( move |conn| {
0 commit comments