|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import { wrapError } from '../client/error_wrapper'; |
8 | | -import { RouteInitialization } from '../types'; |
| 8 | +import { RouteInitialization, SavedObjectsRouteDeps } from '../types'; |
9 | 9 | import { checksFactory, repairFactory } from '../saved_objects'; |
10 | | -import { jobsAndSpaces, repairJobObjects } from './schemas/saved_objects'; |
| 10 | +import { jobsAndSpaces, repairJobObjects, jobTypeSchema } from './schemas/saved_objects'; |
| 11 | +import { jobIdsSchema } from './schemas/job_service_schema'; |
11 | 12 |
|
12 | 13 | /** |
13 | 14 | * Routes for job saved object management |
14 | 15 | */ |
15 | | -export function savedObjectsRoutes({ router, routeGuard }: RouteInitialization) { |
| 16 | +export function savedObjectsRoutes( |
| 17 | + { router, routeGuard }: RouteInitialization, |
| 18 | + { getSpaces, resolveMlCapabilities }: SavedObjectsRouteDeps |
| 19 | +) { |
16 | 20 | /** |
17 | 21 | * @apiGroup JobSavedObjects |
18 | 22 | * |
@@ -220,4 +224,50 @@ export function savedObjectsRoutes({ router, routeGuard }: RouteInitialization) |
220 | 224 | } |
221 | 225 | }) |
222 | 226 | ); |
| 227 | + |
| 228 | + /** |
| 229 | + * @apiGroup JobSavedObjects |
| 230 | + * |
| 231 | + * @api {get} /api/ml/saved_objects/delete_job_check Check whether user can delete a job |
| 232 | + * @apiName DeleteJobCheck |
| 233 | + * @apiDescription Check the user's ability to delete jobs. Returns whether they are able |
| 234 | + * to fully delete the job and whether they are able to remove it from |
| 235 | + * the current space. |
| 236 | + * |
| 237 | + * @apiSchema (body) jobIdsSchema (params) jobTypeSchema |
| 238 | + * |
| 239 | + */ |
| 240 | + router.post( |
| 241 | + { |
| 242 | + path: '/api/ml/saved_objects/can_delete_job/{jobType}', |
| 243 | + validate: { |
| 244 | + params: jobTypeSchema, |
| 245 | + body: jobIdsSchema, |
| 246 | + }, |
| 247 | + options: { |
| 248 | + tags: ['access:ml:canGetJobs', 'access:ml:canGetDataFrameAnalytics'], |
| 249 | + }, |
| 250 | + }, |
| 251 | + routeGuard.fullLicenseAPIGuard(async ({ request, response, jobSavedObjectService, client }) => { |
| 252 | + try { |
| 253 | + const { jobType } = request.params; |
| 254 | + const { jobIds }: { jobIds: string[] } = request.body; |
| 255 | + |
| 256 | + const { canDeleteJobs } = checksFactory(client, jobSavedObjectService); |
| 257 | + const body = await canDeleteJobs( |
| 258 | + request, |
| 259 | + jobType, |
| 260 | + jobIds, |
| 261 | + getSpaces !== undefined, |
| 262 | + resolveMlCapabilities |
| 263 | + ); |
| 264 | + |
| 265 | + return response.ok({ |
| 266 | + body, |
| 267 | + }); |
| 268 | + } catch (e) { |
| 269 | + return response.customError(wrapError(e)); |
| 270 | + } |
| 271 | + }) |
| 272 | + ); |
223 | 273 | } |
0 commit comments