Example #1
0
        public SongListBaseContract[] GetSongListsForCurrentUser(int ignoreSongId)
        {
            PermissionContext.VerifyLogin();

            var canEditPools = PermissionContext.HasPermission(PermissionToken.EditFeaturedLists);

            return(HandleQuery(session =>
            {
                var ignoredLists = session
                                   .Query <SongInList>()
                                   .Where(sil => sil.Song.Id == ignoreSongId)
                                   .Select(sil => sil.List.Id)
                                   .Distinct()
                                   .ToArray();

                return session.Query <SongList>()
                .WhereNotDeleted()
                .Where(l => !ignoredLists.Contains(l.Id) &&
                       ((l.Author.Id == PermissionContext.LoggedUser.Id && l.FeaturedCategory == SongListFeaturedCategory.Nothing) ||
                        (canEditPools && l.FeaturedCategory == SongListFeaturedCategory.Pools)))
                .OrderBy(l => l.Name)
                .ToArray()
                .Select(l => new SongListBaseContract(l))
                .ToArray();
            }));
        }
Example #2
0
        private void VerifyResourceAccess(IEnumerable <int> ownerIds)
        {
            PermissionContext.VerifyLogin();

            if (!ownerIds.Contains(PermissionContext.LoggedUser.Id))
            {
                throw new NotAllowedException("You do not have access to this resource.");
            }
        }
Example #3
0
        /// <summary>
        /// Disconnects Twitter account for the currently logged in user.
        /// Twitter account can NOT be disconnected if the user has not set a VocaDB password.
        /// </summary>
        /// <exception cref="NoPasswordException">If the user has not set a password.</exception>
        public void DisconnectTwitter()
        {
            PermissionContext.VerifyLogin();

            repository.HandleTransaction(ctx => {
                var user = ctx.GetLoggedUser(PermissionContext);

                user.ClearTwitter();

                ctx.AuditLogger.AuditLog("disconnected twitter");
            });
        }
Example #4
0
        public void ResetAccessKey()
        {
            PermissionContext.VerifyLogin();

            HandleTransaction(session => {
                var user = GetLoggedUser(session);
                user.GenerateAccessKey();

                session.Update(user);

                AuditLog("reset access key", session);
            });
        }
Example #5
0
        public void UpdatePersonalDescription(int albumId, AlbumDetailsContract data)
        {
            PermissionContext.VerifyLogin();

            HandleTransaction(ctx => {
                var album = ctx.Load(albumId);

                EntryPermissionManager.VerifyAccess(PermissionContext, album, EntryPermissionManager.CanEditPersonalDescription);

                album.PersonalDescriptionText     = data.PersonalDescriptionText;
                album.PersonalDescriptionAuthorId = data.PersonalDescriptionAuthor?.Id;

                ctx.Update(album);
                ctx.AuditLogger.AuditLog(string.Format("updated personal description for {0}", entryLinkFactory.CreateEntryLink(album)));
            });
        }
Example #6
0
        public SongListBaseContract[] GetSongListsForCurrentUser(int ignoreSongId)
        {
            PermissionContext.VerifyLogin();

            var canEditPools = PermissionContext.HasPermission(PermissionToken.EditFeaturedLists);

            return(HandleQuery(session => {
                var ignoredSong = session.Load <Song>(ignoreSongId);

                return session.Query <SongList>()
                .Where(l => (l.Author.Id == PermissionContext.LoggedUser.Id && l.FeaturedCategory == SongListFeaturedCategory.Nothing) ||
                       (canEditPools && l.FeaturedCategory == SongListFeaturedCategory.Pools))
                .OrderBy(l => l.Name).ToArray()
                .Where(l => !ignoredSong.ListLinks.Any(i => i.List.Equals(l)))
                .Select(l => new SongListBaseContract(l)).ToArray();
            }));
        }
Example #7
0
        protected User GetLoggedUser(ISession session)
        {
            PermissionContext.VerifyLogin();

            return(session.Load <User>(PermissionContext.LoggedUser.Id));
        }