🐛 Trying to fix develop
This commit is contained in:
@@ -16,7 +16,7 @@ namespace DysonNetwork.Develop.Identity;
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public class BotAccountController(
|
public class BotAccountController(
|
||||||
BotAccountService botService,
|
BotAccountService botService,
|
||||||
DeveloperService developerService,
|
DeveloperService ds,
|
||||||
DevProjectService projectService,
|
DevProjectService projectService,
|
||||||
ILogger<BotAccountController> logger,
|
ILogger<BotAccountController> logger,
|
||||||
AccountClientHelper accounts,
|
AccountClientHelper accounts,
|
||||||
@@ -50,9 +50,9 @@ public class BotAccountController(
|
|||||||
]
|
]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Required] [MaxLength(256)] public string Nick { get; set; } = string.Empty;
|
[Required][MaxLength(256)] public string Nick { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Required] [MaxLength(1024)] public string Slug { get; set; } = string.Empty;
|
[Required][MaxLength(1024)] public string Slug { get; set; } = string.Empty;
|
||||||
|
|
||||||
[MaxLength(128)] public string Language { get; set; } = "en-us";
|
[MaxLength(128)] public string Language { get; set; } = "en-us";
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ public class BotAccountController(
|
|||||||
|
|
||||||
[MaxLength(256)] public string? Nick { get; set; } = string.Empty;
|
[MaxLength(256)] public string? Nick { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Required] [MaxLength(1024)] public string? Slug { get; set; } = string.Empty;
|
[Required][MaxLength(1024)] public string? Slug { get; set; } = string.Empty;
|
||||||
|
|
||||||
[MaxLength(128)] public string? Language { get; set; }
|
[MaxLength(128)] public string? Language { get; set; }
|
||||||
|
|
||||||
@@ -83,11 +83,11 @@ public class BotAccountController(
|
|||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
var developer = await developerService.GetDeveloperByName(pubName);
|
var developer = await ds.GetDeveloperByName(pubName);
|
||||||
if (developer is null)
|
if (developer is null)
|
||||||
return NotFound("Developer not found");
|
return NotFound("Developer not found");
|
||||||
|
|
||||||
if (!await developerService.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
if (!await ds.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
||||||
Shared.Proto.PublisherMemberRole.Viewer))
|
Shared.Proto.PublisherMemberRole.Viewer))
|
||||||
return StatusCode(403, "You must be an viewer of the developer to list bots");
|
return StatusCode(403, "You must be an viewer of the developer to list bots");
|
||||||
|
|
||||||
@@ -108,11 +108,11 @@ public class BotAccountController(
|
|||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
var developer = await developerService.GetDeveloperByName(pubName);
|
var developer = await ds.GetDeveloperByName(pubName);
|
||||||
if (developer is null)
|
if (developer is null)
|
||||||
return NotFound("Developer not found");
|
return NotFound("Developer not found");
|
||||||
|
|
||||||
if (!await developerService.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
if (!await ds.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
||||||
Shared.Proto.PublisherMemberRole.Viewer))
|
Shared.Proto.PublisherMemberRole.Viewer))
|
||||||
return StatusCode(403, "You must be an viewer of the developer to view bot details");
|
return StatusCode(403, "You must be an viewer of the developer to view bot details");
|
||||||
|
|
||||||
@@ -137,11 +137,11 @@ public class BotAccountController(
|
|||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
var developer = await developerService.GetDeveloperByName(pubName);
|
var developer = await ds.GetDeveloperByName(pubName);
|
||||||
if (developer is null)
|
if (developer is null)
|
||||||
return NotFound("Developer not found");
|
return NotFound("Developer not found");
|
||||||
|
|
||||||
if (!await developerService.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
if (!await ds.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
||||||
Shared.Proto.PublisherMemberRole.Editor))
|
Shared.Proto.PublisherMemberRole.Editor))
|
||||||
return StatusCode(403, "You must be an editor of the developer to create a bot");
|
return StatusCode(403, "You must be an editor of the developer to create a bot");
|
||||||
|
|
||||||
@@ -206,11 +206,11 @@ public class BotAccountController(
|
|||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
var developer = await developerService.GetDeveloperByName(pubName);
|
var developer = await ds.GetDeveloperByName(pubName);
|
||||||
if (developer is null)
|
if (developer is null)
|
||||||
return NotFound("Developer not found");
|
return NotFound("Developer not found");
|
||||||
|
|
||||||
if (!await developerService.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
if (!await ds.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
||||||
Shared.Proto.PublisherMemberRole.Editor))
|
Shared.Proto.PublisherMemberRole.Editor))
|
||||||
return StatusCode(403, "You must be an editor of the developer to update a bot");
|
return StatusCode(403, "You must be an editor of the developer to update a bot");
|
||||||
|
|
||||||
@@ -267,11 +267,11 @@ public class BotAccountController(
|
|||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
|
||||||
var developer = await developerService.GetDeveloperByName(pubName);
|
var developer = await ds.GetDeveloperByName(pubName);
|
||||||
if (developer is null)
|
if (developer is null)
|
||||||
return NotFound("Developer not found");
|
return NotFound("Developer not found");
|
||||||
|
|
||||||
if (!await developerService.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
if (!await ds.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id),
|
||||||
Shared.Proto.PublisherMemberRole.Editor))
|
Shared.Proto.PublisherMemberRole.Editor))
|
||||||
return StatusCode(403, "You must be an editor of the developer to delete a bot");
|
return StatusCode(403, "You must be an editor of the developer to delete a bot");
|
||||||
|
|
||||||
@@ -374,7 +374,7 @@ public class BotAccountController(
|
|||||||
AccountId = bot.Id.ToString(),
|
AccountId = bot.Id.ToString(),
|
||||||
Label = request.Label
|
Label = request.Label
|
||||||
};
|
};
|
||||||
|
|
||||||
var createdKey = await accountsReceiver.CreateApiKeyAsync(newKey);
|
var createdKey = await accountsReceiver.CreateApiKeyAsync(newKey);
|
||||||
return Ok(SnApiKey.FromProtoValue(createdKey));
|
return Ok(SnApiKey.FromProtoValue(createdKey));
|
||||||
}
|
}
|
||||||
@@ -443,10 +443,10 @@ public class BotAccountController(
|
|||||||
Account currentUser,
|
Account currentUser,
|
||||||
Shared.Proto.PublisherMemberRole requiredRole)
|
Shared.Proto.PublisherMemberRole requiredRole)
|
||||||
{
|
{
|
||||||
var developer = await developerService.GetDeveloperByName(pubName);
|
var developer = await ds.GetDeveloperByName(pubName);
|
||||||
if (developer == null) return (null, null, null);
|
if (developer == null) return (null, null, null);
|
||||||
|
|
||||||
if (!await developerService.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id), requiredRole))
|
if (!await ds.IsMemberWithRole(developer.PublisherId, Guid.Parse(currentUser.Id), requiredRole))
|
||||||
return (null, null, null);
|
return (null, null, null);
|
||||||
|
|
||||||
var project = await projectService.GetProjectAsync(projectId, developer.Id);
|
var project = await projectService.GetProjectAsync(projectId, developer.Id);
|
||||||
@@ -457,4 +457,4 @@ public class BotAccountController(
|
|||||||
|
|
||||||
return (developer, project, bot);
|
return (developer, project, bot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -97,7 +97,7 @@ public class BotAccountService(
|
|||||||
{
|
{
|
||||||
db.Update(bot);
|
db.Update(bot);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Update the bot account in the Pass service
|
// Update the bot account in the Pass service
|
||||||
@@ -155,9 +155,8 @@ public class BotAccountService(
|
|||||||
public async Task<SnBotAccount?> LoadBotAccountAsync(SnBotAccount bot) =>
|
public async Task<SnBotAccount?> LoadBotAccountAsync(SnBotAccount bot) =>
|
||||||
(await LoadBotsAccountAsync([bot])).FirstOrDefault();
|
(await LoadBotsAccountAsync([bot])).FirstOrDefault();
|
||||||
|
|
||||||
public async Task<List<SnBotAccount>> LoadBotsAccountAsync(IEnumerable<SnBotAccount> bots)
|
public async Task<List<SnBotAccount>> LoadBotsAccountAsync(List<SnBotAccount> bots)
|
||||||
{
|
{
|
||||||
bots = [.. bots];
|
|
||||||
var automatedIds = bots.Select(b => b.Id).ToList();
|
var automatedIds = bots.Select(b => b.Id).ToList();
|
||||||
var data = await accounts.GetBotAccountBatch(automatedIds);
|
var data = await accounts.GetBotAccountBatch(automatedIds);
|
||||||
|
|
||||||
@@ -168,6 +167,6 @@ public class BotAccountService(
|
|||||||
.FirstOrDefault(e => e.AutomatedId == bot.Id);
|
.FirstOrDefault(e => e.AutomatedId == bot.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bots as List<SnBotAccount> ?? [];
|
return bots;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user