Exemplo n.º 1
0
        public virtual async Task ValidateEditInfo(Guid currentUserId, Guid chatId, TChatInfo chatInfo, string serviceName,
                                                   string methodName = null)
        {
            var participant = await ReadChatParticipantStore.Retrieve(chatId, currentUserId);

            if (participant == null || participant.ChatParticipantStatus != ChatParticipantStatus.Active || participant.ChatParticipantType.NotIn(ChatParticipantType.Admin, ChatParticipantType.Moderator, ChatParticipantType.Participant))
            {
                throw new DotChatAccessDeniedException(new ErrorCode(ErrorType.AccessDenied, ErrorModule.Security, ErrorOperation.Edit, ErrorEntity.ChatInfo),
                                                       serviceName, methodName, chatId, currentUserId);
            }
        }
        public virtual async Task ValidateAdd(Guid currentUserId, Guid chatId, Guid userId, ChatParticipantType chatParticipantType, string style, string metadata,
                                              string serviceName, string methodName = null)
        {
            var participant = await ReadChatParticipantStore.Retrieve(chatId, currentUserId);

            if (CanNotAddParticipant(participant))
            {
                throw new DotChatAccessDeniedException(new ErrorCode(ErrorType.AccessDenied, ErrorModule.Security, ErrorOperation.Add, ErrorEntity.Participant),
                                                       serviceName, methodName, chatId, currentUserId);
            }

            if (IsHigherParticipantType(chatParticipantType, participant.ChatParticipantType))
            {
                throw new DotChatAccessDeniedException(new ErrorCode(ErrorType.AccessDeniedDueToSelfElevation, ErrorModule.Security, ErrorOperation.Add, ErrorEntity.ParticipantType),
                                                       serviceName, methodName, chatId, currentUserId);
            }
        }
Exemplo n.º 3
0
        public virtual async Task ValidateGetPage(Guid currentUserId, Guid chatId, IReadOnlyCollection <TMessageFilter> filters, TPagingOptions pagingOptions,
                                                  TPagedResult messagesPage, string serviceName, string methodName = null)
        {
            var participant = await ReadChatParticipantStore.Retrieve(chatId, currentUserId);

            if (participant == null || participant.ChatParticipantStatus != ChatParticipantStatus.Active)
            {
                throw new DotChatAccessDeniedException(new ErrorCode(ErrorType.AccessDenied, ErrorModule.Security, ErrorOperation.Get, ErrorEntity.Message),
                                                       serviceName, methodName, chatId, currentUserId);
            }
        }