Esempio n. 1
0
        async Task <IEnumerable <User> > GetUsersAsync(ISpamOperation operation)
        {
            var roleNames = new List <string>(2);

            if (operation.NotifyAdmin)
            {
                roleNames.Add(DefaultRoles.Administrator);
            }
            if (operation.NotifyStaff)
            {
                roleNames.Add(DefaultRoles.Staff);
            }
            if (roleNames.Count == 0)
            {
                return(null);
            }
            var users = await _platoUserStore.QueryAsync()
                        .Select <UserQueryParams>(q =>
            {
                q.RoleName.IsIn(roleNames.ToArray());
            })
                        .ToList();

            return(users?.Data);
        }
Esempio n. 2
0
 public SpamOperatorResult <TModel> Failed(TModel model, ISpamOperation operation)
 {
     return(new SpamOperatorResult <TModel>()
     {
         Response = model,
         Operation = operation,
         Succeeded = false
     });
 }
Esempio n. 3
0
        async Task <ISpamOperation> GetPersistedOperation(ISpamOperation operation)
        {
            // If the spam operation has been persisted within the database ensure we use
            // the persisted version from the database as opposed to the default operation
            var settings = await _spamSettingsStore.GetAsync();

            var existingOperation = settings?.SpamOperations?.FirstOrDefault(o => o.Name.Equals(operation.Name));

            if (existingOperation != null)
            {
                return(existingOperation);
            }

            return(operation);
        }
Esempio n. 4
0
        public async Task <IEnumerable <ISpamOperatorResult <TModel> > > UpdateModelAsync(ISpamOperation operation, TModel model)
        {
            // Create context for involved providers
            var context = new SpamOperatorContext <TModel>()
            {
                Model     = model,
                Operation = await GetPersistedOperation(operation)
            };

            // Invoke provided operators
            var results = new List <ISpamOperatorResult <TModel> >();

            foreach (var spamOperator in _spamOperators)
            {
                try
                {
                    var result = await spamOperator.UpdateModelAsync(context);

                    if (result != null)
                    {
                        results.Add(result);
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, $"An error occurred whilst invoking the UpdateModelAsync method within a spam operator provider for type '{operation.Name}'.");
                }
            }

            return(results);
        }