@@ -12,6 +12,7 @@ use bcr_ebill_core::application::company::{
1212 Company , CompanySignatory , CompanySignatoryStatus , CompanyStatus , LocalSignatoryOverrideStatus ,
1313} ;
1414use bcr_ebill_core:: application:: contact:: Contact ;
15+ use bcr_ebill_core:: application:: identity:: ActiveIdentityState ;
1516use bcr_ebill_core:: application:: { ServiceTraitBounds , ValidationError } ;
1617use bcr_ebill_core:: protocol:: Identification ;
1718use bcr_ebill_core:: protocol:: Name ;
@@ -593,7 +594,7 @@ impl CompanyServiceApi for CompanyService {
593594 . process_upload_file (
594595 & proof_of_registration_file_upload_id,
595596 & id,
596- & full_identity . key_pair . pub_key ( ) ,
597+ & company_keys . pub_key ( ) ,
597598 nostr_relay,
598599 UploadFileType :: Document ,
599600 )
@@ -603,7 +604,7 @@ impl CompanyServiceApi for CompanyService {
603604 . process_upload_file (
604605 & logo_file_upload_id,
605606 & id,
606- & full_identity . key_pair . pub_key ( ) ,
607+ & company_keys . pub_key ( ) ,
607608 nostr_relay,
608609 UploadFileType :: Picture ,
609610 )
@@ -859,7 +860,7 @@ impl CompanyServiceApi for CompanyService {
859860 self . process_upload_file (
860861 & logo_file_upload_id,
861862 id,
862- & full_identity . key_pair . pub_key ( ) ,
863+ & company_keys . pub_key ( ) ,
863864 nostr_relay,
864865 UploadFileType :: Picture ,
865866 )
@@ -876,7 +877,7 @@ impl CompanyServiceApi for CompanyService {
876877 self . process_upload_file (
877878 & proof_of_registration_file_upload_id,
878879 id,
879- & full_identity . key_pair . pub_key ( ) ,
880+ & company_keys . pub_key ( ) ,
880881 nostr_relay,
881882 UploadFileType :: Document ,
882883 )
@@ -1106,7 +1107,19 @@ impl CompanyServiceApi for CompanyService {
11061107 ) ) ;
11071108 }
11081109 let company_keys = self . store . get_key_pair ( id) . await ?;
1109- if company. signatories . len ( ) == 1 {
1110+ // Only count fully accepted signatories
1111+ if company
1112+ . signatories
1113+ . iter ( )
1114+ . filter ( |s| {
1115+ matches ! (
1116+ s. status,
1117+ CompanySignatoryStatus :: InviteAcceptedIdentityProven { .. }
1118+ )
1119+ } )
1120+ . count ( )
1121+ == 1
1122+ {
11101123 return Err ( super :: Error :: Validation (
11111124 ProtocolValidationError :: CantRemoveLastSignatory . into ( ) ,
11121125 ) ) ;
@@ -1186,6 +1199,25 @@ impl CompanyServiceApi for CompanyService {
11861199 if let Err ( e) = self . company_blockchain_store . remove ( id) . await {
11871200 error ! ( "Could not delete local company chain for {id}: {e}" ) ;
11881201 }
1202+ // If the current active identity is the company we're removed from - set to personal identity
1203+ if let Ok ( Some ( active_node_id) ) = self
1204+ . identity_store
1205+ . get_current_identity ( )
1206+ . await
1207+ . map ( |i| i. company )
1208+ && & active_node_id == id
1209+ && let Err ( e) = self
1210+ . identity_store
1211+ . set_current_identity ( & ActiveIdentityState {
1212+ personal : full_identity. identity . node_id ,
1213+ company : None ,
1214+ } )
1215+ . await
1216+ {
1217+ error ! (
1218+ "Couldn't set active identity to personal after removing self from company: {e}"
1219+ ) ;
1220+ }
11891221 }
11901222 debug ! (
11911223 "removed signatory {} to company with id: {id}" ,
@@ -3287,6 +3319,12 @@ pub mod tests {
32873319 key_pair : keys_clone_clone. clone ( ) ,
32883320 } )
32893321 } ) ;
3322+ identity_store. expect_get_current_identity ( ) . returning ( || {
3323+ Ok ( ActiveIdentityState {
3324+ personal : node_id_test ( ) ,
3325+ company : None ,
3326+ } )
3327+ } ) ;
32903328 storage. expect_update ( ) . returning ( |_, _| Ok ( ( ) ) ) ;
32913329 storage. expect_remove ( ) . returning ( |_| Ok ( ( ) ) ) ;
32923330 identity_chain_store
0 commit comments