예제 #1
0
        public async Task <IHttpActionResult> DeleteGroups([FromBody] OperationScope scope, string search = null)
        {
            SearchFieldValidator.Validate(search);

            if (scope == null)
            {
                return(BadRequest(ErrorMessages.InvalidDeleteGroupsParameters));
            }

            if (scope.IsEmpty())
            {
                return(Ok(DeleteResult.Empty));
            }

            await _privilegesManager.Demand(Session.UserId, InstanceAdminPrivileges.ManageGroups);

            var deletedGroupIds = new List <int>();
            Func <IDbTransaction, long, Task> action = async(transaction, transactionId) =>
            {
                var groupIds = await _groupRepository.DeleteGroupsAsync(scope, search, transaction);

                deletedGroupIds.AddRange(groupIds);

                var topRevisionId = await _itemInfoRepository.GetTopRevisionId(transaction);

                var message = new UsersGroupsChangedMessage(new int[0], deletedGroupIds)
                {
                    TransactionId = transactionId,
                    RevisionId    = topRevisionId,
                    ChangeType    = UsersGroupsChangedType.Delete
                };
                await _sendMessageExecutor.Execute(_applicationSettingsRepository, _serviceLogRepository, message, transaction);
            };

            await RunInTransactionAsync(action);

            return(Ok(new DeleteResult {
                TotalDeleted = deletedGroupIds.Count
            }));
        }
예제 #2
0
        private async Task PostOperation(IEnumerable <int> artifactIds, int revisionId, int userId, long transactionId, IDbTransaction transaction = null)
        {
            if (artifactIds.IsEmpty())
            {
                return;
            }

            var message = new ArtifactsChangedMessage(artifactIds)
            {
                TransactionId = transactionId,
                RevisionId    = revisionId,
                UserId        = userId,
                ChangeType    = ArtifactChangedType.Publish
            };

            await _sendMessageExecutor.Execute(_applicationSettingsRepository, _serviceLogRepository, message, transaction);
        }