示例#1
0
        private async Task <EntitiesResult <AccountType> > SetIsActive(List <int> ids, ActionArguments args, bool isActive)
        {
            await Initialize();

            // Check user permissions
            var action       = "IsActive";
            var actionFilter = await UserPermissionsFilter(action, cancellation : default);

            ids = await CheckActionPermissionsBefore(actionFilter, ids);

            // Execute and return
            using var trx = TransactionFactory.ReadCommitted();
            OperationOutput output = await _behavior.Repository.AccountTypes__Activate(
                ids : ids,
                isActive : isActive,
                validateOnly : ModelState.IsError,
                top : ModelState.RemainingErrors,
                userId : UserId);

            AddErrorsAndThrowIfInvalid(output.Errors);

            var result = (args.ReturnEntities ?? false) ?
                         await GetByIds(ids, args, action, cancellation : default) :
                         EntitiesResult <AccountType> .Empty();

            // Check user permissions again
            await CheckActionPermissionsAfter(actionFilter, ids, result.Data);

            trx.Complete();
            return(result);
        }
        public async Task <EntitiesResult <ResourceDefinition> > UpdateState(List <int> ids, UpdateStateArguments args)
        {
            await Initialize();

            // Check user permissions
            var action       = "State";
            var actionFilter = await UserPermissionsFilter(action, cancellation : default);

            ids = await CheckActionPermissionsBefore(actionFilter, ids);

            // C# Validation
            if (string.IsNullOrWhiteSpace(args.State))
            {
                throw new ServiceException(_localizer[ErrorMessages.Error_Field0IsRequired, _localizer["State"]]);
            }

            if (!DefStates.All.Contains(args.State))
            {
                string validStates = string.Join(", ", DefStates.All);
                throw new ServiceException($"'{args.State}' is not a valid definition state, valid states are: {validStates}");
            }

            // Execute and return
            using var trx = TransactionFactory.ReadCommitted();
            OperationOutput output = await _behavior.Repository.ResourceDefinitions__UpdateState(
                ids : ids,
                state : args.State,
                validateOnly : ModelState.IsError,
                top : ModelState.RemainingErrors,
                userId : UserId);

            AddErrorsAndThrowIfInvalid(output.Errors);

            // Prepare result
            var result = (args.ReturnEntities ?? false) ?
                         await GetByIds(ids, args, action, cancellation : default) :
                         EntitiesResult <ResourceDefinition> .Empty();

            // Check user permissions again
            await CheckActionPermissionsAfter(actionFilter, ids, result.Data);

            trx.Complete();
            return(result);
        }
示例#3
0
        private async Task <EntitiesResult <Currency> > SetIsActive(List <string> ids, ActionArguments args, bool isActive)
        {
            await Initialize();

            // Check user permissions
            var action       = "IsActive";
            var actionFilter = await UserPermissionsFilter(action, cancellation : default);

            ids = await CheckActionPermissionsBefore(actionFilter, ids);

            var settings = await _behavior.Settings();

            foreach (var(id, index) in ids.Indexed())
            {
                if (ids.Any(id => id != null && id == settings.FunctionalCurrencyId))
                {
                    string path = $"[{index}]";
                    string msg  = _localizer["Error_CannotDeactivateTheFunctionalCurrency"];

                    ModelState.AddError(path, msg);
                }
            }

            // Execute and return
            using var trx = TransactionFactory.ReadCommitted();
            OperationOutput output = await _behavior.Repository.Currencies__Activate(
                ids : ids,
                isActive : isActive,
                validateOnly : ModelState.IsError,
                top : ModelState.RemainingErrors,
                userId : UserId);

            AddErrorsAndThrowIfInvalid(output.Errors);

            var result = (args.ReturnEntities ?? false) ?
                         await GetByIds(ids, args, action, cancellation : default) :
                         EntitiesResult <Currency> .Empty();

            // Check user permissions again
            await CheckActionPermissionsAfter(actionFilter, ids, result.Data);

            trx.Complete();
            return(result);
        }
示例#4
0
        public async Task <EntitiesResult <IdentityServerClient> > ResetClientSecret(ResetClientSecretArguments args)
        {
            await Initialize();

            // Check permissions
            var idSingleton = new List <int> {
                args.Id
            };                                           // A single Id
            var action       = PermissionActions.Update;
            var actionFilter = await UserPermissionsFilter(action, cancellation : default);

            idSingleton = await CheckActionPermissionsBefore(actionFilter, idSingleton);

            // Invisible or missing user
            if (!idSingleton.Any())
            {
                // The user cannot view that user, we pretend it doesn't exist
                throw new NotFoundException <int>(args.Id);
            }

            // Reset the secret
            var newSecret = CryptographicallyStrongClientSecret();

            using var trx = TransactionFactory.ReadCommitted();
            await _behavior.Repository.IdentityServerClients__UpdateSecret(args.Id, newSecret, UserId);


            var result = (args.ReturnEntities ?? false) ?
                         await GetByIds(idSingleton, args, action, cancellation : default) :
                         EntitiesResult <IdentityServerClient> .Empty();

            // Check user permissions again
            await CheckActionPermissionsAfter(actionFilter, idSingleton, result.Data);

            trx.Complete();
            return(result);
        }
        public async Task <EntitiesResult <DocumentDefinition> > UpdateState(List <int> ids, UpdateStateArguments args)
        {
            await Initialize();

            // Check user permissions
            var action       = "State";
            var actionFilter = await UserPermissionsFilter(action, cancellation : default);

            ids = await CheckActionPermissionsBefore(actionFilter, ids);

            // Validation
            if (string.IsNullOrWhiteSpace(args.State))
            {
                throw new ServiceException(_localizer[ErrorMessages.Error_Field0IsRequired, _localizer["State"]]);
            }

            if (!DefStates.All.Contains(args.State))
            {
                string validStates = string.Join(", ", DefStates.All);
                throw new ServiceException($"'{args.State}' is not a valid definition state, valid states are: {validStates}.");
            }

            var defs = await _behavior.Definitions();

            int jvDefId = defs.ManualJournalVouchersDefinitionId;

            int index = 0;

            ids.ForEach(id =>
            {
                if (id == jvDefId)
                {
                    string path = $"[{index}]";
                    string msg  = _localizer["Error_CannotModifySystemItem"];

                    ModelState.AddError(path, msg);
                }

                index++;
            });

            // Execute
            using var trx = TransactionFactory.ReadCommitted();
            OperationOutput output = await _behavior.Repository.DocumentDefinitions__UpdateState(
                ids : ids,
                state : args.State,
                validateOnly : ModelState.IsError,
                top : ModelState.RemainingErrors,
                userId : UserId);

            AddErrorsAndThrowIfInvalid(output.Errors);

            // Prepare result
            var result = (args.ReturnEntities ?? false) ?
                         await GetByIds(ids, args, action, cancellation : default) :
                         EntitiesResult <DocumentDefinition> .Empty();

            // Check user permissions again
            await CheckActionPermissionsAfter(actionFilter, ids, result.Data);

            trx.Complete();
            return(result);
        }