2024-05-21 20:55:12 +00:00
|
|
|
using BotSharp.Abstraction.Users.Enums;
|
|
|
|
|
|
2023-06-23 04:43:00 +00:00
|
|
|
namespace BotSharp.Core.Agents.Services;
|
|
|
|
|
|
|
|
|
|
public partial class AgentService
|
|
|
|
|
{
|
|
|
|
|
public async Task<bool> DeleteAgent(string id)
|
|
|
|
|
{
|
2024-05-21 20:55:12 +00:00
|
|
|
var user = _db.GetUserById(_user.Id);
|
2024-10-31 19:36:26 +00:00
|
|
|
var userAgents = await GetUserAgents(user?.Id);
|
|
|
|
|
var found = userAgents?.FirstOrDefault(x => x.AgentId == id);
|
2024-05-21 20:55:12 +00:00
|
|
|
|
2024-10-31 19:36:26 +00:00
|
|
|
if (!UserConstant.AdminRoles.Contains(user?.Role) && (found?.Actions == null || !found.Actions.Contains(UserAction.Edit)))
|
2024-05-21 20:55:12 +00:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var deleted = _db.DeleteAgent(id);
|
|
|
|
|
return await Task.FromResult(deleted);
|
2023-06-23 04:43:00 +00:00
|
|
|
}
|
|
|
|
|
}
|