Esempio n. 1
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                await QueryValidationHelper.CheckUserExistsAsync(callContext.DbContext, UserId);

                await QueryValidationHelper.CheckCardExistsAsync(callContext.DbContext, CardId);

                if (Rating < 1 || Rating > 5)
                {
                    throw new RequestInputException($"Invalid rating: {Rating}");
                }
            }
Esempio n. 2
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                await QueryValidationHelper.CheckUserExistsAsync(callContext.DbContext, UserId);

                if (CultureName != CultureName.Trim())
                {
                    throw new InvalidOperationException("Invalid Name: not trimmed");
                }
                if (CultureName.Length < MinNameLength || CultureName.Length > MaxNameLength)
                {
                    throw new InvalidOperationException($"Invalid culture name '{CultureName}'");
                }
            }
Esempio n. 3
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                await QueryValidationHelper.CheckCanCreateLanguageWithName(Name, callContext.DbContext, callContext.Localized);

                await QueryValidationHelper.CheckUserExistsAsync(callContext.DbContext, UserId);

                var user = await callContext.DbContext.Users.AsNoTracking().SingleAsync(user => user.Id == UserId);

                if (!await callContext.RoleChecker.UserIsAdminAsync(user))
                {
                    throw new InvalidOperationException("User not admin");
                }
            }
Esempio n. 4
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                await QueryValidationHelper.CheckUserExistsAsync(callContext.DbContext, UserId);

                if (CardIds.Any(cardId => QueryValidationHelper.IsReservedGuid(cardId)))
                {
                    throw new RequestInputException($"Invalid card id");
                }
                CardVisibilityHelper.CheckUserIsAllowedToViewCards(callContext.DbContext, UserId, CardIds.ToArray());
                foreach (var cardId in CardIds)
                {
                    await CheckUsersWithCardInADeckAsync(cardId, callContext.DbContext, callContext.Localized);
                    await CheckCardVersionsCreatorsAsync(cardId, callContext.DbContext, callContext.Localized);
                }
            }
Esempio n. 5
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                if (LoggedUserId != UserToDeleteId)
                {
                    await QueryValidationHelper.CheckUserExistsAndIsAdminAsync(callContext.DbContext, LoggedUserId, callContext.RoleChecker);
                }

                await QueryValidationHelper.CheckUserExistsAsync(callContext.DbContext, UserToDeleteId);

                var userToDelete = await callContext.DbContext.Users.AsNoTracking().SingleAsync(user => user.Id == UserToDeleteId);

                if (await callContext.RoleChecker.UserIsAdminAsync(userToDelete))
                {
                    //Additional security: forbid deleting an admin account
                    throw new InvalidOperationException("User to delete is admin");
                }
            }
 public async Task CheckValidityAsync(CallContext callContext)
 {
     await QueryValidationHelper.CheckUserExistsAsync(callContext.DbContext, UserId);
 }
Esempio n. 7
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                await QueryValidationHelper.CheckUserExistsAsync(callContext.DbContext, UserId);

                await QueryValidationHelper.CheckCanCreateTag(Name, Description, null, callContext.DbContext, callContext.Localized);
            }
Esempio n. 8
0
            public async Task CheckValidityAsync(MemCheckDbContext dbContext)
            {
                await QueryValidationHelper.CheckUserExistsAsync(dbContext, UserId);

                await QueryValidationHelper.CheckUserIsOwnerOfDeckAsync(dbContext, UserId, DeckId);
            }