diff --git a/src/Tgstation.Server.Api/Models/ErrorCode.cs b/src/Tgstation.Server.Api/Models/ErrorCode.cs
index 2f6821868d..36f14a5ee0 100644
--- a/src/Tgstation.Server.Api/Models/ErrorCode.cs
+++ b/src/Tgstation.Server.Api/Models/ErrorCode.cs
@@ -608,5 +608,17 @@ namespace Tgstation.Server.Api.Models
///
[Description("Cannot delete the user group as it is not empty!")]
UserGroupNotEmpty,
+
+ ///
+ /// Attempted to create an but the configured limit has been reached.
+ ///
+ [Description("The user cannot be created because the configured limit has been reached!")]
+ UserLimitReached,
+
+ ///
+ /// Attempted to create an but the configured limit has been reached.
+ ///
+ [Description("The user group cannot be created because the configured limit has been reached!")]
+ UserGroupLimitReached,
}
}
diff --git a/src/Tgstation.Server.Host/Controllers/UserController.cs b/src/Tgstation.Server.Host/Controllers/UserController.cs
index 6acadfae0a..ffd098b961 100644
--- a/src/Tgstation.Server.Host/Controllers/UserController.cs
+++ b/src/Tgstation.Server.Host/Controllers/UserController.cs
@@ -139,6 +139,14 @@ namespace Tgstation.Server.Host.Controllers
if (fail != null)
return fail;
+ var totalUsers = await DatabaseContext
+ .Users
+ .AsQueryable()
+ .CountAsync(cancellationToken)
+ .ConfigureAwait(false);
+ if (totalUsers >= generalConfiguration.UserLimit)
+ return Conflict(new ErrorMessage(ErrorCode.UserLimitReached));
+
var dbUser = await CreateNewUserFromModel(model, cancellationToken).ConfigureAwait(false);
if (dbUser == null)
return Gone();
diff --git a/src/Tgstation.Server.Host/Controllers/UserGroupController.cs b/src/Tgstation.Server.Host/Controllers/UserGroupController.cs
index c1be2818ad..d666e0b748 100644
--- a/src/Tgstation.Server.Host/Controllers/UserGroupController.cs
+++ b/src/Tgstation.Server.Host/Controllers/UserGroupController.cs
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
using System;
using System.Linq;
using System.Threading;
@@ -8,6 +9,7 @@ using System.Threading.Tasks;
using Tgstation.Server.Api;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Rights;
+using Tgstation.Server.Host.Configuration;
using Tgstation.Server.Host.Database;
using Tgstation.Server.Host.Security;
using Z.EntityFramework.Plus;
@@ -20,15 +22,22 @@ namespace Tgstation.Server.Host.Controllers
[Route(Routes.UserGroup)]
public class UserGroupController : ApiController
{
+ ///
+ /// The for the .
+ ///
+ readonly GeneralConfiguration generalConfiguration;
+
///
/// Initializes a new instance of the .
///
/// The for the
/// The for the
+ /// The containing the value of .
/// The for the .
public UserGroupController(
IDatabaseContext databaseContext,
IAuthenticationContextFactory authenticationContextFactory,
+ IOptions generalConfigurationOptions,
ILogger logger)
: base(
databaseContext,
@@ -36,6 +45,7 @@ namespace Tgstation.Server.Host.Controllers
logger,
true)
{
+ generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
}
///
@@ -56,6 +66,14 @@ namespace Tgstation.Server.Host.Controllers
if (model.Name == null)
return BadRequest(new ErrorMessage(ErrorCode.ModelValidationFailure));
+ var totalGroups = await DatabaseContext
+ .Groups
+ .AsQueryable()
+ .CountAsync(cancellationToken)
+ .ConfigureAwait(false);
+ if (totalGroups >= generalConfiguration.UserGroupLimit)
+ return Conflict(new ErrorMessage(ErrorCode.UserGroupLimitReached));
+
var permissionSet = new Models.PermissionSet
{
AdministrationRights = model.PermissionSet?.AdministrationRights ?? AdministrationRights.None,