mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-03 20:17:59 +00:00 
			
		
		
		
	* Add getRelativePath helper and use to calculate relativeNamespace * Always request capabilities-self on users root ns and prefix body with relative path * Update capabilities adapter with test * add changelog * Simplify getRelativePath logic * test update
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/**
 | 
						|
 * Copyright (c) HashiCorp, Inc.
 | 
						|
 * SPDX-License-Identifier: BUSL-1.1
 | 
						|
 */
 | 
						|
 | 
						|
import AdapterError from '@ember-data/adapter/error';
 | 
						|
import { set } from '@ember/object';
 | 
						|
import ApplicationAdapter from './application';
 | 
						|
import { sanitizePath } from 'core/utils/sanitize-path';
 | 
						|
 | 
						|
export default ApplicationAdapter.extend({
 | 
						|
  pathForType() {
 | 
						|
    return 'capabilities-self';
 | 
						|
  },
 | 
						|
 | 
						|
  formatPaths(path) {
 | 
						|
    const { relativeNamespace } = this.namespaceService;
 | 
						|
    if (!relativeNamespace) {
 | 
						|
      return [path];
 | 
						|
    }
 | 
						|
    // ensure original path doesn't have leading slash
 | 
						|
    return [`${relativeNamespace}/${path.replace(/^\//, '')}`];
 | 
						|
  },
 | 
						|
 | 
						|
  findRecord(store, type, id) {
 | 
						|
    const paths = this.formatPaths(id);
 | 
						|
    return this.ajax(this.buildURL(type), 'POST', {
 | 
						|
      data: { paths },
 | 
						|
      namespace: sanitizePath(this.namespaceService.userRootNamespace),
 | 
						|
    }).catch((e) => {
 | 
						|
      if (e instanceof AdapterError) {
 | 
						|
        set(e, 'policyPath', 'sys/capabilities-self');
 | 
						|
      }
 | 
						|
      throw e;
 | 
						|
    });
 | 
						|
  },
 | 
						|
 | 
						|
  queryRecord(store, type, query) {
 | 
						|
    const { id } = query;
 | 
						|
    if (!id) {
 | 
						|
      return;
 | 
						|
    }
 | 
						|
    return this.findRecord(store, type, id).then((resp) => {
 | 
						|
      resp.path = id;
 | 
						|
      return resp;
 | 
						|
    });
 | 
						|
  },
 | 
						|
});
 |