Beispiel #1
0
        public async Task <bool> VerifyAccess(APEntity entity, string userId)
        {
            if (entity.Type == "_blocks" && !entity.Data["attributedTo"].Any(a => a.Id == userId))
            {
                return(false);
            }
            if (entity.Type == "_blocked")
            {
                return(false);
            }
            if (entity.Type == "https://www.w3.org/ns/activitystreams#OrderedCollection" || entity.Type == "https://www.w3.org/ns/activitystreams#Collection" || entity.Type.StartsWith("_"))
            {
                return(true);
            }
            if (_entityData.IsActor(entity.Data))
            {
                return(true);
            }

            var audience = DeliveryService.GetAudienceIds(entity.Data);

            return(
                entity.Data["attributedTo"].Concat(entity.Data["actor"]).Any(a => a.Id == userId) ||
                audience.Contains("https://www.w3.org/ns/activitystreams#Public") ||
                (userId != null && audience.Contains(userId))
                );
        }
Beispiel #2
0
        public async Task <CollectionItem> AddToCollection(APEntity collection, APEntity entity)
        {
            var ci = new CollectionItem
            {
                Collection = collection,
                Element    = entity,
                IsPublic   = DeliveryService.IsPublic(entity.Data)
            };

            await _context.CollectionItems.AddAsync(ci);

            return(ci);
        }
Beispiel #3
0
        private bool _verifyAudience(string user, CollectionItem entity)
        {
            if (entity.IsPublic)
            {
                return(true);
            }
            if (_configuration.IsActor(entity.Element.Data))
            {
                return(true);
            }
            var audience = DeliveryService.GetAudienceIds(entity.Element.Data);

            return(audience.Contains(user));
        }
Beispiel #4
0
        public async Task <CollectionItem> AddToCollection(APEntity collection, APEntity entity)
        {
            var ci = new CollectionItem
            {
                CollectionId = collection.DbId,
                ElementId    = entity.DbId,
                IsPublic     = DeliveryService.IsPublic(entity.Data) || _configuration.IsActor(entity.Data)
            };


            await _connection.ExecuteAsync("insert into \"CollectionItems\" (\"CollectionId\", \"ElementId\", \"IsPublic\") values (@CollectionId, @ElementId, @IsPublic)", ci);

            await _notifier.Notify($"collection/{collection.Id}", entity.Id);

            return(ci);
        }