add Job Tasks to enable the execution of adhoc asynchronous site-based workloads
This commit is contained in:
63
Oqtane.Server/Controllers/JobTaskController.cs
Normal file
63
Oqtane.Server/Controllers/JobTaskController.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oqtane.Enums;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
[Route(ControllerRoutes.ApiRoute)]
|
||||
public class JobTaskController : Controller
|
||||
{
|
||||
private readonly IJobTaskRepository _jobTasks;
|
||||
private readonly ILogManager _logger;
|
||||
private readonly Alias _alias;
|
||||
|
||||
public JobTaskController(IJobTaskRepository jobTasks, ILogManager logger, ITenantManager tenantManager)
|
||||
{
|
||||
_jobTasks = jobTasks;
|
||||
_logger = logger;
|
||||
_alias = tenantManager.GetAlias();
|
||||
}
|
||||
|
||||
// GET api/<controller>/5
|
||||
[HttpGet("{id}")]
|
||||
[Authorize(Roles = RoleNames.Admin)]
|
||||
public JobTask Get(int id)
|
||||
{
|
||||
var jobTask = _jobTasks.GetJobTask(id);
|
||||
if (jobTask.SiteId == _alias.SiteId)
|
||||
{
|
||||
return jobTask;
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// POST api/<controller>
|
||||
[HttpPost]
|
||||
[Authorize(Roles = RoleNames.Admin)]
|
||||
public JobTask Post([FromBody] JobTask jobTask)
|
||||
{
|
||||
if (ModelState.IsValid && jobTask.SiteId == _alias.SiteId)
|
||||
{
|
||||
jobTask.IsCompleted = false;
|
||||
jobTask = _jobTasks.AddJobTask(jobTask);
|
||||
_logger.Log(LogLevel.Information, this, LogFunction.Create, "Job Task Added {JobTask}", jobTask);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Job Task Post Attempt {JobTask}", jobTask);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
jobTask = null;
|
||||
}
|
||||
return jobTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,42 +418,6 @@ namespace Oqtane.Controllers
|
||||
return requirements;
|
||||
}
|
||||
|
||||
// POST api/<controller>/import?siteid=x&fileid=y¬ify=z
|
||||
[HttpPost("import")]
|
||||
[Authorize(Roles = RoleNames.Admin)]
|
||||
public async Task<Dictionary<string, string>> Import(string siteid, string fileid, string notify)
|
||||
{
|
||||
if (int.TryParse(siteid, out int SiteId) && SiteId == _tenantManager.GetAlias().SiteId && int.TryParse(fileid, out int FileId) && bool.TryParse(notify, out bool Notify))
|
||||
{
|
||||
var file = _files.GetFile(FileId);
|
||||
if (file != null)
|
||||
{
|
||||
if (_userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.PermissionList))
|
||||
{
|
||||
return await _userManager.ImportUsers(SiteId, _files.GetFilePath(file), Notify);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized User Import Attempt {SiteId} {FileId}", siteid, fileid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Import File Does Not Exist {SiteId} {FileId}", siteid, fileid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized User Import Attempt {SiteId} {FileId}", siteid, fileid);
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// GET: api/<controller>/passkey?id=x
|
||||
[HttpGet("passkey")]
|
||||
[Authorize]
|
||||
|
||||
Reference in New Issue
Block a user