Esempio n. 1
0
        public async Task <bool> CanEditAsync(Guid id)
        {
            var cached = await GetAsync(id);

            if (IsGroupHidden(_groupActivityService.GetGroupId(id)))
            {
                return(false);
            }
            return(await CanEditAsync(cached));
        }
Esempio n. 2
0
        private async Task <bool> CanAddRemoveLikeAsync(Guid entityId, IntranetEntityTypeEnum entityType)
        {
            if (entityType.Is(IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Events))
            {
                var member = await _intranetMemberService.GetCurrentMemberAsync();

                var activityGroupId = _groupActivityService.GetGroupId(entityId);

                if (activityGroupId.HasValue)
                {
                    var group = _groupService.Get(activityGroupId.Value);
                    if (group == null || group.IsHidden)
                    {
                        return(false);
                    }
                }

                if (activityGroupId.HasValue && !member.GroupIds.Contains(activityGroupId.Value))
                {
                    return(false);
                }
            }
            else if (entityType.Is(IntranetEntityTypeEnum.Comment))
            {
                var comment = await _commentsService.GetAsync(entityId);

                var activityType = _activityTypeHelper.GetActivityType(comment.ActivityId);

                return(await CanAddRemoveLikeAsync(comment.ActivityId, (IntranetEntityTypeEnum)activityType));
            }

            return(true);
        }
Esempio n. 3
0
 private bool IsHiddenGroup(CommentModel comment)
 {
     var groupId = _groupActivityService.GetGroupId(comment.ActivityId);
     if (groupId.HasValue)
     {
         var group = _groupService.Get(groupId.Value);
         if (group == null || group.IsHidden)
             return true;
     }
     return false;
 }
Esempio n. 4
0
 protected override void MapBeforeCache(IList <Entities.News> cached)
 {
     foreach (var activity in cached)
     {
         var entity = activity;
         entity.Location = _activityLocationService.Get(entity.Id);
         entity.GroupId  = _groupActivityService.GetGroupId(activity.Id);
         _commentsService.FillComments(entity);
         _likesService.FillLikes(entity);
     }
 }
Esempio n. 5
0
 protected override void MapBeforeCache(IList <Bulletin> cached)
 {
     foreach (var activity in cached)
     {
         var entity = activity;
         entity.GroupId = _groupActivityService.GetGroupId(activity.Id);
         _commentsService.FillComments(entity);
         _likesService.FillLikes(entity);
         FillLinkPreview(entity);
     }
 }
Esempio n. 6
0
 protected override void MapBeforeCache(IList <Event> cached)
 {
     foreach (var activity in cached)
     {
         var entity = activity;
         entity.GroupId = _groupActivityService.GetGroupId(activity.Id);
         _subscribeService.FillSubscribers(entity);
         _commentsService.FillComments(entity);
         _likesService.FillLikes(entity);
         _activitySubscribeSettingService.FillSubscribeSettings(entity);
     }
 }
Esempio n. 7
0
        public GroupInfo?GetGroupInfo(Guid activityId)
        {
            var groupId = _groupActivityService
                          .GetGroupId(activityId);

            if (!groupId.HasValue)
            {
                return(null);
            }

            return(GetInfoForGroup(groupId.Value));
        }
Esempio n. 8
0
        public IActivityLinks GetLinks(Guid activityId)
        {
            var groupId = _groupActivityService.GetGroupId(activityId);

            var activity = GetActivity(activityId);

            if (!groupId.HasValue)
            {
                return(_centralFeedLinkProvider.GetLinks(activity.Map <ActivityTransferModel>()));
            }

            var activityModel = activity.Map <GroupActivityTransferModel>();

            activityModel.GroupId = groupId.Value;
            return(_groupFeedLinkProvider.GetLinks(activityModel));
        }
Esempio n. 9
0
        public IActivityLinks GetLinks(Guid activityId)
        {
            var groupId = _groupActivityService.GetGroupId(activityId);

            var            activity = GetActivity(activityId);
            IActivityLinks result;

            if (groupId.HasValue)
            {
                var activityModel = activity.Map <GroupActivityTransferModel>();
                result = _groupFeedLinkProvider.GetLinks(activityModel);
            }
            else
            {
                var activityModel = activity.Map <ActivityTransferModel>();
                result = _centralFeedLinkProvider.GetLinks(activityModel);
            }
            return(result);
        }
Esempio n. 10
0
        public async Task <IHttpActionResult> Add([FromBody] CommentCreateModel model)
        {
            if (model.EntityType.Is(IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Events))
            {
                var member = await _intranetMemberService.GetCurrentMemberAsync();

                var activityGroupId = _groupActivityService.GetGroupId(model.EntityId);

                if (activityGroupId.HasValue)
                {
                    var group = _groupService.Get(activityGroupId.Value);
                    if (group == null || group.IsHidden)
                    {
                        return(StatusCode(HttpStatusCode.Forbidden));
                    }
                }

                if (activityGroupId.HasValue && !member.GroupIds.Contains(activityGroupId.Value))
                {
                    return(StatusCode(HttpStatusCode.Forbidden));
                }
            }

            var createDto = await MapToCreateDtoAsync(model, model.EntityId);

            var command = new AddCommentCommand(model.EntityId, model.EntityType, createDto);

            _commandPublisher.Publish(command);

            await OnCommentCreatedAsync(createDto.Id, model.EntityType);

            switch (model.EntityType)
            {
            case IntranetEntityTypeEnum type
                when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events):
                var activityCommentsInfo = GetActivityComments(model.EntityId);

                return(Ok(await _commentsHelper.OverViewAsync(activityCommentsInfo.Id, activityCommentsInfo.Comments, activityCommentsInfo.IsReadOnly)));

            default:
                return(Ok(await _commentsHelper.OverViewAsync(model.EntityId)));
            }
        }
        public override ConverterResponseModel MapViewModel(LikesPanelModel node, LikesPanelViewModel viewModel)
        {
            var activityId = _context.ParseQueryString("id").TryParseGuid();

            var activityType = activityId.HasValue
                ? _activityTypeHelper.GetActivityType(activityId.Value)
                : IntranetActivityTypeEnum.ContentPage;

            var id = activityType.Equals(IntranetActivityTypeEnum.ContentPage)
                ? _requestContext.Node?.Key
                : activityId;

            if (!id.HasValue)
            {
                return(NotFoundResult());
            }

            var groupId = _groupActivityService.GetGroupId(id.Value);

            var currentMember = _intranetMemberService.GetCurrentMember();

            viewModel.IsGroupMember = !groupId.HasValue || currentMember.GroupIds.Contains(groupId.Value);

            if (!viewModel.IsGroupMember)
            {
                return(ForbiddenResult());
            }

            var likes = _likesService.GetLikeModels(id.Value).ToArray();

            viewModel.Likes              = likes;
            viewModel.EntityId           = id.Value;
            viewModel.LikedByCurrentUser = likes.Any(el => el.UserId == currentMember.Id);
            viewModel.ActivityType       = activityType;

            return(OkResult());
        }
Esempio n. 12
0
        public override ConverterResponseModel MapViewModel(CommentsPanelModel node, CommentsPanelViewModel viewModel)
        {
            var activityId = _context.ParseQueryString("id").TryParseGuid();

            var activityType = activityId.HasValue
                ? _activityTypeHelper.GetActivityType(activityId.Value)
                : IntranetEntityTypeEnum.ContentPage;

            var id = activityType.Equals(IntranetEntityTypeEnum.ContentPage)
                ? _requestContext.Node?.Key
                : activityId;

            if (!id.HasValue)
            {
                return(NotFoundResult());
            }

            var groupId = _groupActivityService.GetGroupId(id.Value);

            var currentMember = _intranetMemberService.GetCurrentMember();

            viewModel.IsGroupMember = !groupId.HasValue || currentMember.GroupIds.Contains(groupId.Value);

            if (!viewModel.IsGroupMember)
            {
                return(ForbiddenResult());
            }

            var comments = _commentsService.GetMany(id.Value);

            viewModel.Comments     = _commentsHelper.GetCommentViews(comments);
            viewModel.EntityId     = id.Value;
            viewModel.CommentsType = activityType;

            return(OkResult());
        }
Esempio n. 13
0
        private bool IsGroupActivity(IEnumerable <Guid> groupIds, IFeedItem item)
        {
            var assignedGroupId = _groupActivityService.GetGroupId(item.Id);

            return(assignedGroupId.HasValue && groupIds.Contains(assignedGroupId.Value) && !_groupService.Get(assignedGroupId.Value).IsHidden);
        }
Esempio n. 14
0
 public GroupInfo?GetGroupInfo(Guid activityId) =>
 _groupActivityService
 .GetGroupId(activityId)
 .Apply(GetInfoForGroup);