Skip to content

Commit

Permalink
Limit max themes per user to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Jan 2, 2024
1 parent aadcde8 commit 2d25431
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion DeckPersonalisationApi/Controllers/SubmissionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ public class SubmissionController : Controller
private UserService _user;
private BlobService _blob;
private AppConfiguration _config;
private ThemeService _themes;

public SubmissionController(JwtService jwt, SubmissionService submission, UserService user, BlobService blob, AppConfiguration config)
public SubmissionController(JwtService jwt, SubmissionService submission, UserService user, BlobService blob, AppConfiguration config, ThemeService themes)
{
_jwt = jwt;
_submission = submission;
_user = user;
_blob = blob;
_config = config;
_themes = themes;
}

[HttpPost("css_git")]
Expand Down Expand Up @@ -202,6 +204,9 @@ private void ValidateMeta(User user, SubmissionMeta meta, ThemeType type)

if (meta.PrivateSubmission && DiscordBot.Instance.PermissionStateOfUser(user.Id) == "None")
throw new BadRequestException("Can only create private themes on premium account");

if (_themes.GetThemeCountOfUser(user) >= _config.MaxThemeCount)
throw new BadRequestException("Theme limit reached");
}

private void CheckIfUserIsAllowedToMakeSubmission(User user)
Expand Down
2 changes: 2 additions & 0 deletions DeckPersonalisationApi/Services/AppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class AppConfiguration
public long MaxEmailLength { get; private set; }
public long MaxDescriptionLength { get; private set; }
public long MaxCssOnlySubmissionSize { get; private set; }
public long MaxThemeCount { get; private set; }
public long MaxErrorStoreCharacters { get; private set; }
public long DiscordServerId { get; private set; }
public long DiscordPremiumTier1Role { get; private set; }
Expand Down Expand Up @@ -134,6 +135,7 @@ private void SetValues()
MaxEmailLength = GetInt("Config:MaxEmailLength");
MaxCssOnlySubmissionSize = GetInt("Config:MaxCssOnlySubmissionSize");
MaxErrorStoreCharacters = GetInt("Config:MaxErrorStoreCharacters");
MaxThemeCount = GetInt("Config:MaxThemeCountPerUser");

DiscordServerId = GetInt("Config:DiscordServerId");
DiscordPremiumTier1Role = GetInt("Config:PremiumTier1Role");
Expand Down
3 changes: 3 additions & 0 deletions DeckPersonalisationApi/Services/ThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public IEnumerable<CssTheme> GetThemesByIds(List<string> ids, bool strict = true
public bool ThemeNameExists(string name, ThemeType type)
=> _ctx.CssThemes.Any(x => x.Name == name && x.Visibility == PostVisibility.Public && x.Type == type);

public int GetThemeCountOfUser(User user)
=> _ctx.CssThemes.Count(x => x.Author.Id == user.Id && x.Visibility != PostVisibility.Deleted);

public List<LegacyThemesDto> GetThemesLegacy(ThemeType type, PostVisibility visibility)
=> _ctx.CssThemes
.Include(x => x.Images)
Expand Down
1 change: 1 addition & 0 deletions DeckPersonalisationApi/appsettings.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"MaxDescriptionLength": "1000",
"MaxCssOnlySubmissionSize": "2000",
"MaxErrorStoreCharacters": "4096",
"MaxThemeCountPerUser": "100",
"DiscordServerId": "1051660079033745478",
"PremiumTier1Role": "1077305620346175498",
"PremiumTier2Role": "1077306197939585036",
Expand Down

0 comments on commit 2d25431

Please sign in to comment.