public void HandleAttemptLockOfCurrentBook(ApiRequest request) { if (!_tcManager.CheckConnection()) { request.Failed(); return; } try { // Could be a problem if there's no current book or it's not in the collection folder. // But in that case, we don't show the UI that leads to this being called. var success = _tcManager.CurrentCollection.AttemptLock(BookFolderName); if (success) { UpdateUiForBook(); Analytics.Track("TeamCollectionCheckoutBook", new Dictionary <string, string>() { { "CollectionId", _settings?.CollectionId }, { "CollectionName", _settings?.CollectionName }, { "Backend", _tcManager?.CurrentCollection?.GetBackendType() }, { "User", CurrentUser }, { "BookId", _bookSelection?.CurrentSelection?.ID }, { "BookName", _bookSelection?.CurrentSelection?.Title } }); } request.ReplyWithBoolean(success); } catch (Exception e) { var msg = MakeLockFailedMessageFromException(e, BookFolderName); // Pushing an error into the log will show the Reload Collection button. It's not obvious this // is useful here, since we don't know exactly what went wrong. However, it at least gives the user // the option to try it. var log = _tcManager?.CurrentCollection?.MessageLog; if (log != null) { log.WriteMessage(msg); } Logger.WriteError(msg.TextForDisplay, e); NonFatalProblem.ReportSentryOnly(e, $"Something went wrong for {request.LocalPath()}"); request.Failed("lock failed"); } }
private void HandleForceUnlock(ApiRequest request) { if (!_tcManager.CheckConnection()) { request.Failed(); return; } try { var bookStatus = _tcManager.CurrentCollection.GetStatus(BookFolderName); var lockedBy = bookStatus.lockedByFirstName; if (string.IsNullOrEmpty(lockedBy)) { lockedBy = bookStatus.lockedBy; } // Could be a problem if there's no current book or it's not in the collection folder. // But in that case, we don't show the UI that leads to this being called. _tcManager.CurrentCollection.ForceUnlock(BookFolderName); BookHistory.AddEvent(_bookSelection.CurrentSelection, BookHistoryEventType.ForcedUnlock, $"Admin force-unlocked while checked out to {lockedBy}."); UpdateUiForBook(); Analytics.Track("TeamCollectionRevertOtherCheckout", new Dictionary <string, string>() { { "CollectionId", _settings?.CollectionId }, { "CollectionName", _settings?.CollectionName }, { "Backend", _tcManager?.CurrentCollection?.GetBackendType() }, { "User", CurrentUser }, { "BookId", _bookSelection?.CurrentSelection?.ID }, { "BookName", _bookSelection?.CurrentSelection?.Title } }); request.PostSucceeded(); } catch (Exception e) { NonFatalProblem.Report(ModalIf.All, PassiveIf.All, "Could not force unlock", null, e, true); request.Failed("could not unlock"); } }