raise DashboardException(msg='Unable to delete "{}" - this user '
'account is required for managing the '
'Object Gateway'.format(uid))
- # Finally redirect request to the RGW proxy.
- return self.proxy(daemon_name, 'DELETE', 'user', {'uid': uid}, json_response=False)
+ daemon_name_to_use = daemon_name if daemon_name else instance.daemon.name
+ user_instance = RgwClient.get_cached_user_instance(daemon_name_to_use, uid)
+ result = self.proxy(daemon_name, 'DELETE', 'user', {'uid': uid}, json_response=False)
+ # Only invalidate cache after successful deletion to prevent negative cache hits
+ # when the user is recreated with the same UID. This fixes the issue where
+ # Dashboard fails to authenticate after deleting and recreating a user.
+ if user_instance:
+ RgwClient.drop_instance(user_instance)
+ return result
except (DashboardException, RequestException) as e: # pragma: no cover
raise DashboardException(e, component='rgw')
def admin_instance(daemon_name: Optional[str] = None) -> 'RgwClient':
return RgwClient.instance(daemon_name=daemon_name)
+ @staticmethod
+ def get_cached_user_instance(daemon_name: str, userid: str) -> Optional['RgwClient']:
+ """
+ Get a cached user instance if it exists.
+
+ :param daemon_name: The daemon name
+ :param userid: The user ID
+ :return: The cached RgwClient instance or None if not found
+ """
+ if daemon_name in RgwClient._user_instances and \
+ userid in RgwClient._user_instances[daemon_name]:
+ return RgwClient._user_instances[daemon_name][userid]
+ return None
+
@staticmethod
def drop_instance(instance: Optional['RgwClient'] = None):
"""