private void TestCanDelete(bool expected, EntryStatus entryStatus = EntryStatus.Finished, UserGroupId userGroup = UserGroupId.Regular)
        {
            artist.Status = entryStatus;
            user.GroupId  = userGroup;

            var result = EntryPermissionManager.CanDelete(new FakePermissionContext(user), artist);

            Assert.AreEqual(expected, result, "result");
        }
Example #2
0
 public TagForEditContract(Tag tag, bool isEmpty, IUserPermissionContext userContext)
     : base(tag, userContext.LanguagePreference)
 {
     CanDelete           = EntryPermissionManager.CanDelete(userContext, tag);
     DefaultNameLanguage = tag.TranslatedName.DefaultLanguage;
     Description         = new EnglishTranslatedStringContract(tag.Description);
     IsEmpty             = isEmpty;
     Names       = tag.Names.Select(n => new LocalizedStringWithIdContract(n)).ToArray();
     RelatedTags = tag.RelatedTags.Select(t => new TagBaseContract(t.LinkedTag, userContext.LanguagePreference, false)).ToArray();
     Thumb       = (tag.Thumb != null ? new EntryThumbContract(tag.Thumb) : null);
     UpdateNotes = string.Empty;
     WebLinks    = tag.WebLinks.Links.Select(w => new WebLinkContract(w)).OrderBy(w => w.DescriptionOrUrl).ToArray();
 }
 private ArtistEditViewModel CreateArtistEditViewModel(int id, ArtistForEditContract editedArtist)
 {
     return(queries.Get(id, album => new ArtistEditViewModel(new ArtistContract(album, PermissionContext.LanguagePreference), PermissionContext,
                                                             EntryPermissionManager.CanDelete(PermissionContext, album), editedArtist)));
 }
Example #4
0
        public async Task <ActionResult> Edit(SongEditViewModel viewModel)
        {
            // Unable to continue if viewmodel is null because we need the ID at least
            if (viewModel?.EditedSong == null)
            {
                log.Warn("Viewmodel was null");
                return(HttpStatusCodeResult(HttpStatusCode.BadRequest, "Viewmodel was null - probably JavaScript is disabled"));
            }

            try {
                viewModel.CheckModel();
            } catch (InvalidFormException x) {
                AddFormSubmissionError(x.Message);
            }

            var model = viewModel.EditedSong;

            // Note: name is allowed to be whitespace, but not empty.
            if (model.Names == null || model.Names.All(n => n == null || string.IsNullOrEmpty(n.Value)))
            {
                ModelState.AddModelError("Names", SongValidationErrors.UnspecifiedNames);
            }

            if (model.Lyrics != null && model.Lyrics.Any(n => string.IsNullOrEmpty(n.Value)))
            {
                ModelState.AddModelError("Lyrics", "Lyrics cannot be empty");
            }

            if (!ModelState.IsValid)
            {
                return(View(Service.GetSong(model.Id, song => new SongEditViewModel(new SongContract(song, PermissionContext.LanguagePreference, false),
                                                                                    PermissionContext, EntryPermissionManager.CanDelete(PermissionContext, song), InstrumentalTagId, model))));
            }

            await queries.UpdateBasicProperties(model);

            return(RedirectToAction("Details", new { id = model.Id, albumId = viewModel.AlbumId }));
        }
Example #5
0
        public ActionResult Edit(int id, int?albumId = null)
        {
            CheckConcurrentEdit(EntryType.Song, id);

            var model = Service.GetSong(id, song => new SongEditViewModel(new SongContract(song, PermissionContext.LanguagePreference, false),
                                                                          PermissionContext, EntryPermissionManager.CanDelete(PermissionContext, song), InstrumentalTagId, albumId: albumId));

            return(View(model));
        }
Example #6
0
 private AlbumEditViewModel CreateAlbumEditViewModel(int id, AlbumForEditContract editedAlbum)
 {
     return(Service.GetAlbum(id, album => new AlbumEditViewModel(new AlbumContract(album, PermissionContext.LanguagePreference), PermissionContext,
                                                                 EntryPermissionManager.CanDelete(PermissionContext, album), editedAlbum)));
 }
 private bool CanDelete <T>(User user, T entry) where T : IEntryWithVersions, IEntryWithStatus
 {
     return(EntryPermissionManager.CanDelete(new FakePermissionContext(user), entry));
 }