@@ -92,6 +92,10 @@ function set_pool_controller_factory(pool_controller_factory) {
92
92
// and only allows deletion in case that the owner is also the requester of the deletion
93
93
function check_deletion_ownership ( req , resource_owner_id ) {
94
94
if ( config . RESTRICT_RESOURCE_DELETION ) {
95
+ if ( ! resource_owner_id ) {
96
+ dbg . error ( 'check_deletion_ownership: pool has no owner' ) ;
97
+ throw new RpcError ( 'INTERNAL_ERROR' , 'The pool has no owner, and thus cannot be deleted' ) ;
98
+ }
95
99
const requester_is_sys_owner = String ( req . account . _id ) === String ( req . system . owner . _id ) ;
96
100
if ( ! requester_is_sys_owner && String ( resource_owner_id ) !== String ( req . account . _id ) ) {
97
101
dbg . error ( 'check_deletion_ownership: requester (' , req . account . _id , ') is not the owner (' , resource_owner_id , ') of the resource' ) ;
@@ -652,7 +656,9 @@ async function update_hosts_pool(req) {
652
656
653
657
function delete_pool ( req ) {
654
658
const pool = find_pool_by_name ( req ) ;
655
- check_deletion_ownership ( req , pool . owner_id ) ;
659
+ // rebuild_object_links() resolves the pool's owner_id to the account object
660
+ // which is why we have to access ._id to get the actual ID
661
+ check_deletion_ownership ( req , pool . owner_id ?. _id ) ;
656
662
if ( pool . hosts_pool_info ) {
657
663
return delete_hosts_pool ( req , pool ) ;
658
664
} else {
@@ -662,7 +668,7 @@ function delete_pool(req) {
662
668
663
669
function delete_namespace_resource ( req ) {
664
670
const ns = find_namespace_resource_by_name ( req ) ;
665
- check_deletion_ownership ( req , ns . account ) ;
671
+ check_deletion_ownership ( req , ns . account . _id ) ;
666
672
dbg . log0 ( 'Deleting namespace resource' , ns . name ) ;
667
673
return P . resolve ( )
668
674
. then ( ( ) => {
0 commit comments