public ActionResult ViewSysLog() { PermissionContext.VerifyPermission(PermissionToken.ViewAuditLog); var logContents = new LogFileReader().GetLatestLogFileContents(); return(Content(logContents, "text/plain")); //return View(new ViewSysLog(logContents)); }
private void MoveTopic(IDatabaseContext ctx, DiscussionTopic topic, int targetFolderId) { PermissionContext.VerifyPermission(PermissionToken.DeleteComments); var folder = ctx.Load <DiscussionFolder>(targetFolderId); ctx.AuditLogger.AuditLog(string.Format("Moving {0} to {1}", topic, folder)); topic.MoveToFolder(folder); }
public int GetNewReportsCount() { PermissionContext.VerifyPermission(PermissionToken.ManageEntryReports); return(HandleQuery(ctx => { var cutoff = DateTime.Now - TimeSpan.FromDays(7); var count = ctx.Query().Count(r => r.Created >= cutoff); return count; })); }
public EntryReportContract[] GetEntryReports() { PermissionContext.VerifyPermission(PermissionToken.ManageEntryReports); return(HandleQuery(session => { var reports = session.Query <EntryReport>().OrderByDescending(r => r.Created).Take(200).ToArray(); var fac = new EntryForApiContractFactory(null, null); return reports.Select(r => new EntryReportContract(r, fac.Create(r.EntryBase, EntryOptionalFields.AdditionalNames, LanguagePreference, false), enumTranslations)).ToArray(); })); }
public void UpdateAlbumForUser(int userId, int albumId, PurchaseStatus status, MediaType mediaType, int rating) { PermissionContext.VerifyPermission(PermissionToken.EditProfile); HandleTransaction(session => { var albumForUser = session.Query <AlbumForUser>() .FirstOrDefault(a => a.Album.Id == albumId && a.User.Id == userId); // Delete if (albumForUser != null && status == PurchaseStatus.Nothing && rating == 0) { AuditLog(string.Format("deleting {0} for {1}", CreateEntryLink(albumForUser.Album), albumForUser.User), session); NHibernateUtil.Initialize(albumForUser.Album.CoverPictureData); albumForUser.Delete(); session.Delete(albumForUser); session.Update(albumForUser.Album); // Add } else if (albumForUser == null && (status != PurchaseStatus.Nothing || rating != 0)) { var user = session.Load <User>(userId); var album = session.Load <Album>(albumId); NHibernateUtil.Initialize(album.CoverPictureData); albumForUser = user.AddAlbum(album, status, mediaType, rating); session.Save(albumForUser); session.Update(album); AuditLog(string.Format("added {0} for {1}", CreateEntryLink(album), user), session); // Update } else if (albumForUser != null) { albumForUser.MediaType = mediaType; albumForUser.PurchaseStatus = status; session.Update(albumForUser); if (albumForUser.Rating != rating) { albumForUser.Rating = rating; albumForUser.Album.UpdateRatingTotals(); NHibernateUtil.Initialize(albumForUser.Album.CoverPictureData); session.Update(albumForUser.Album); } AuditLog(string.Format("updated {0} for {1}", CreateEntryLink(albumForUser.Album), albumForUser.User), session); } }); }
public ActionResult Edit(int id) { PermissionContext.VerifyPermission(PermissionToken.ManageUserPermissions); var user = Service.GetUserWithPermissions(id); return(View(new UserEdit(user) { EditableGroups = UserEdit.GetEditableGroups(_loginManager) })); }
public EntryReportContract[] GetEntryReports() { PermissionContext.VerifyPermission(PermissionToken.ManageEntryReports); return(HandleQuery(session => { var reports = session.Query <EntryReport>().OrderByDescending(r => r.Created).Take(200).ToArray(); var fac = new EntryReportContractFactory(); return reports.Select(r => fac.Create(r, PermissionContext.LanguagePreference)).ToArray(); })); }
public ActionResult ManageIPRules([FromJson] IPRule[] rules) { PermissionContext.VerifyPermission(PermissionToken.ManageIPRules); Service.UpdateIPRules(rules); ipRuleManager.Reset(rules.Select(i => i.Address)); TempData.SetSuccessMessage("IP rules updated."); return(View(rules)); }
public AlbumContract AcceptImportedAlbum(ImportedAlbumOptions importedAlbum, int[] selectedSongIds) { PermissionContext.VerifyPermission(PermissionToken.MikuDbImport); return(HandleTransaction(session => { var inspected = Inspect(session, importedAlbum); var album = AcceptImportedAlbum(session, importedAlbum.SelectedLanguage, inspected, selectedSongIds); return album; })); }
public void UpdateContentLanguagePreference(ContentLanguagePreference languagePreference) { PermissionContext.VerifyPermission(PermissionToken.EditProfile); HandleTransaction(session => { var user = GetLoggedUser(session); user.DefaultLanguageSelection = languagePreference; session.Update(user); }); }
public ActionResult ManageIPRules([ModelBinder(BinderType = typeof(JsonModelBinder))] IPRule[] rules) { PermissionContext.VerifyPermission(PermissionToken.ManageIPRules); Service.UpdateIPRules(rules); _ipRuleManager.Reset(rules.Select(i => i.Address)); TempData.SetSuccessMessage("IP rules updated."); return(View(rules)); }
public void UpdateAlbumForUserRating(int albumForUserId, int rating) { PermissionContext.VerifyPermission(PermissionToken.EditProfile); HandleTransaction(session => { var albumForUser = session.Load <AlbumForUser>(albumForUserId); albumForUser.Rating = rating; albumForUser.Album.UpdateRatingTotals(); session.Update(albumForUser.Album); }); }
public void Restore(int songId) { PermissionContext.VerifyPermission(PermissionToken.DeleteEntries); HandleTransaction(session => { var song = session.Load <Song>(songId); song.Deleted = false; AuditLog("restored " + EntryLinkFactory.CreateEntryLink(song), session); }); }
/// <summary> /// Permanently deletes a message by Id. /// </summary> /// <param name="messageId">Id of the message to be deleted.</param> public void Delete(int messageId) { PermissionContext.VerifyPermission(PermissionToken.EditProfile); repository.HandleTransaction(ctx => { var msg = ctx.Load(messageId); DoDelete(ctx, msg); ctx.AuditLogger.SysLog(string.Format("deleted {0}", msg)); }); }
public void Restore(int albumId) { PermissionContext.VerifyPermission(PermissionToken.DeleteEntries); HandleTransaction(session => { var album = session.Load <Album>(albumId); album.Deleted = false; AuditLog("restored " + EntryLinkFactory.CreateEntryLink(album), session); }); }
public ActionResult Edit(UserEdit model, IEnumerable <PermissionFlagEntry> permissions) { PermissionContext.VerifyPermission(PermissionToken.ManageUserPermissions); if (permissions != null) { model.Permissions = permissions.ToArray(); } Data.UpdateUser(model.ToContract()); return(RedirectToAction("Details", new { id = model.Id })); }
public ActionResult ClearCaches() { PermissionContext.VerifyPermission(PermissionToken.Admin); var cache = MemoryCache.Default; foreach (var item in cache) { cache.Remove(item.Key); } return(RedirectToAction("Index")); }
public ActionResult UpdateArtistString(int id) { PermissionContext.VerifyPermission(PermissionToken.Admin); queries.HandleTransaction(ctx => { var song = ctx.Load(id); song.UpdateArtistString(); ctx.Update(song); ctx.AuditLogger.SysLog("Updated artist string for " + song); }); return(RedirectToAction("Details", new { id })); }
public async Task <ActionResult> CheckSFS(string ip) { PermissionContext.VerifyPermission(PermissionToken.ManageUserPermissions); var result = await new StopForumSpamClient().CallApiAsync(ip); if (result == null) { return(new EmptyResult()); } return(PartialView("Partials/_SFSCheckResponse", result)); }
public ArchivedArtistVersionDetailsContract GetVersionDetails(int id, int comparedVersionId) { return(HandleQuery(session => { var contract = new ArchivedArtistVersionDetailsContract(session.Load <ArchivedArtistVersion>(id), comparedVersionId != 0 ? session.Load <ArchivedArtistVersion>(comparedVersionId) : null, PermissionContext); if (contract.Hidden) { PermissionContext.VerifyPermission(PermissionToken.ViewHiddenRevisions); } return contract; })); }
public void Restore(int tagId) { PermissionContext.VerifyPermission(PermissionToken.DeleteEntries); HandleTransaction(session => { var tag = session.Load <Tag>(tagId); tag.Deleted = false; Archive(session, tag, new TagDiff(false), EntryEditEvent.Updated); AuditLog("restored " + entryLinkFactory.CreateEntryLink(tag), session); }); }
public ActionResult AuditLogEntries(ViewAuditLogModel model, int start = 0) { PermissionContext.VerifyPermission(PermissionToken.ViewAuditLog); var excludeUsers = (!string.IsNullOrEmpty(model.ExcludeUsers) ? model.ExcludeUsers.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(u => u.Trim()).ToArray() : new string[0]); var cutoffDays = (string.IsNullOrEmpty(model.UserName) ? 365 : 0); var entries = Service.GetAuditLog(model.Filter, start, 200, cutoffDays, model.UserName, excludeUsers, model.OnlyNewUsers, model.GroupId); return(PartialView(entries)); }
public void RemoveAlbumFromUser(int userId, int albumId) { PermissionContext.VerifyPermission(PermissionToken.EditProfile); HandleTransaction(session => { var link = session.Query <AlbumForUser>().FirstOrDefault(a => a.Album.Id == albumId && a.User.Id == userId); if (link != null) { AuditLog("deleting " + link, session); session.Delete(link); } }); }
public void Restore(int artistId) { PermissionContext.VerifyPermission(PermissionToken.DeleteEntries); HandleTransaction(session => { var artist = session.Load <Artist>(artistId); NHibernateUtil.Initialize(artist.Picture); artist.Deleted = false; session.Update(artist); AuditLog("restored " + EntryLinkFactory.CreateEntryLink(artist), session); }); }
protected int RemoveTagUsage <T>(long tagUsageId) where T : TagUsage { PermissionContext.VerifyPermission(PermissionToken.RemoveTagUsages); return(HandleTransaction(session => { var tagUsage = session.Load <T>(tagUsageId); AuditLog(string.Format("removing {0}", tagUsage), session); tagUsage.Delete(); session.Delete(tagUsage); return tagUsage.Entry.Id; })); }
public void DeleteSongList(int listId) { PermissionContext.VerifyPermission(PermissionToken.EditProfile); HandleTransaction(session => { var user = GetLoggedUser(session); var list = session.Load <SongList>(listId); EntryPermissionManager.VerifyEdit(PermissionContext, list); session.Delete(list); AuditLog(string.Format("deleted {0}", list.ToString()), session, user); }); }
public ActionResult UpdateThumbUrl(int id) { PermissionContext.VerifyPermission(PermissionToken.AccessManageMenu); queries.HandleTransaction(ctx => { var song = ctx.Load(id); song.UpdateThumbUrl(); ctx.Update(song); ctx.AuditLogger.SysLog("Updated thumbnail URL for " + song); }); TempData.SetSuccessMessage("Thumbnail refreshed"); return(RedirectToAction("Details", new { id })); }
public void RestoreSeries(int eventId) { PermissionContext.VerifyPermission(PermissionToken.DeleteEntries); HandleTransaction(ctx => { var ev = ctx.Load <ReleaseEventSeries>(eventId); ev.Deleted = false; ctx.Update(ev); Archive(ctx, ev, new ReleaseEventSeriesDiff(false), EntryEditEvent.Restored, string.Empty); ctx.AuditLogger.AuditLog(string.Format("restored {0}", ev)); }); }
public void Delete(string name) { ParamIs.NotNullOrEmpty(() => name); PermissionContext.VerifyPermission(PermissionToken.DeleteEntries); repository.HandleTransaction(ctx => { var tag = ctx.Load(name); tag.Delete(); ctx.AuditLogger.AuditLog(string.Format("deleted {0}", tag)); ctx.Delete(tag); }); }
public int ImportFromFile(Stream stream) { PermissionContext.VerifyPermission(PermissionToken.MikuDbImport); var parser = new AlbumFileParser(); var imported = parser.Parse(stream); return(HandleTransaction(session => { SysLog(string.Format("importing album from file with name '{0}'", imported.Title)); var newAlbum = new MikuDbAlbum(imported); session.Save(newAlbum); return newAlbum.Id; })); }