public async Task <IActionResult> DeleteServer(int id)
        {
            if (!await RightsHandler.HasRightsToThisPavlovServer(HttpContext.User,
                                                                 await _userservice.getUserFromCp(HttpContext.User), id, _service, _pavlovServerService))
            {
                return(Forbid());
            }
            try
            {
                await _pavlovServerService.Delete(id);
            }
            catch (CommandException e)
            {
                return(BadRequest(e.Message));
            }

            return(RedirectToAction("Index", "SshServer"));
        }
        public void DeletePavlovServer()
        {
            // arrange
            var sshServer     = SshServerServiceTests.SshServerInsert(_sshServerSerivce);
            var pavlovServers = PavlovServers(sshServer, _pavlovServerService);

            pavlovServers.Should().NotBeNullOrEmpty();
            // act
            _pavlovServerService.Delete(pavlovServers.FirstOrDefault().Id).GetAwaiter().GetResult();
            // assert
            var pavlovServersAfterDelete = _pavlovServerService.FindAll().GetAwaiter().GetResult();

            pavlovServersAfterDelete.Should().BeEmpty();
        }
Beispiel #3
0
        public async Task <IActionResult> RemovePavlovServer(string apiKey, int sshServerId, int pavlovServerId)
        {
            if (!HasAccess(apiKey))
            {
                return(BadRequest("No AuthKey set or wrong auth key!"));
            }
            var sshServer = await _sshServerSerivce.FindOne(sshServerId);

            var pavlovServer = await _pavlovServerService.FindOne(pavlovServerId);

            if (sshServer == null)
            {
                return(BadRequest("The ssh server does not exist!"));
            }
            if (!sshServer.IsForHosting)
            {
                return(BadRequest("The ssh server ist not for hosting!"));
            }
            var viewmodel = new PavlovServerViewModel();

            viewmodel = viewmodel.fromPavlovServer(pavlovServer, sshServerId);
            //todo add admin
            viewmodel.remove             = true;
            viewmodel.SshPassphraseRoot  = sshServer.SshPassphraseRootForHosting;
            viewmodel.SshPasswordRoot    = sshServer.SshPasswordRootForHosting;
            viewmodel.SshUsernameRoot    = sshServer.SshUsernameRootForHosting;
            viewmodel.SshKeyFileNameRoot = sshServer.SshKeyFileNameRootForHosting;
            try
            {
                await _sshServerSerivce.RemovePavlovServerFromDisk(viewmodel, false);
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
            await _pavlovServerService.Delete(pavlovServer.Id);

            return(Ok());
        }