import rbd
-from . import ApiController, RESTController, Task, UpdatePermission
+from . import ApiController, RESTController, Task, UpdatePermission, DeletePermission
from .. import mgr
from ..security import Scope
from ..services.ceph_service import CephService
return _rbd_call(pool_name, _parent_clone)
-@ApiController('/block/image/trash')
+@ApiController('/block/image/trash', Scope.RBD_IMAGE)
class RbdTrash(RESTController):
RESOURCE_ID = "pool_name/image_id"
rbd_inst = rbd.RBD()
@handle_rados_error('pool')
@RbdTask('trash/purge', ['{pool_name}'], 2.0)
@RESTController.Collection('POST', query_params=['pool_name'])
+ @DeletePermission
def purge(self, pool_name=None):
"""Remove all expired images from trash."""
now = "{}Z".format(datetime.now().isoformat())
@RbdTask('trash/restore', ['{pool_name}', '{image_id}', '{new_image_name}'], 2.0)
@RESTController.Resource('POST')
+ @UpdatePermission
def restore(self, pool_name, image_id, new_image_name):
"""Restore an image from trash."""
return _rbd_call(pool_name, self.rbd_inst.trash_restore, image_id, new_image_name)
import { ToastModule } from 'ng2-toastr';
import { of } from 'rxjs';
+import { By } from '@angular/platform-browser';
import { configureTestBed } from '../../../../testing/unit-test-helper';
import { RbdService } from '../../../shared/api/rbd.service';
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
expectImageTasks(component.images[1], 'Restoring');
});
});
+
+ describe('display purge button', () => {
+ beforeEach(() => {});
+
+ it('should show button with delete permission', () => {
+ component.permission = {
+ read: true,
+ create: true,
+ delete: true,
+ update: true
+ };
+ fixture.detectChanges();
+
+ const purge = fixture.debugElement.query(By.css('.table-actions button .fa-times'));
+ expect(purge).not.toBeNull();
+ });
+
+ it('should remove button without delete permission', () => {
+ component.permission = {
+ read: true,
+ create: true,
+ delete: false,
+ update: true
+ };
+ fixture.detectChanges();
+
+ const purge = fixture.debugElement.query(By.css('.table-actions button .fa-times'));
+ expect(purge).toBeNull();
+ });
+ });
});