-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some minor bugs around history
- Loading branch information
Showing
8 changed files
with
234 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 21 additions & 9 deletions
30
devops/girder/plugins/AnnotationPlugin/upenncontrast_annotation/server/api/history.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,54 @@ | ||
from girder.api import access | ||
from girder.api.describe import Description, describeRoute | ||
from girder.api.rest import Resource | ||
from girder.constants import SortDir, AccessType | ||
from girder.exceptions import AccessException | ||
from girder.exceptions import AccessException, RestException | ||
from ..models.history import History as HistoryModel | ||
from bson.objectid import ObjectId | ||
|
||
class History(Resource): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.resourceName = 'history' | ||
|
||
self._historyModel = HistoryModel() | ||
self._historyModel: HistoryModel = HistoryModel() | ||
|
||
self.route('GET', (), self.find) | ||
self.route('PUT', ('undo',), self.undo) | ||
self.route('PUT', ('redo',), self.redo) | ||
|
||
@access.user | ||
@describeRoute(Description("Get last history actions for the user, from the most recent to the oldest")) | ||
@describeRoute(Description("Get last history actions for the user, from the most recent to the oldest") | ||
.param('datasetId', 'The dataset in which are the history entries', required=True)) | ||
def find(self, params): | ||
user = self.getCurrentUser() | ||
if user is None: | ||
raise AccessException('You must be logged in.') | ||
return self._historyModel.getLastEntries(user) | ||
if 'datasetId' not in params: | ||
raise RestException(code=400, message='Dataset ID is missing') | ||
datasetId = ObjectId(params['datasetId']) | ||
return self._historyModel.getLastEntries(user, datasetId) | ||
|
||
@access.user | ||
@describeRoute(Description("Undo the last history entry which hasn't been undone")) | ||
@describeRoute(Description("Undo the last history entry which hasn't been undone") | ||
.param('datasetId', 'The dataset in which undo should be done', required=True)) | ||
def undo(self, params): | ||
user = self.getCurrentUser() | ||
if user is None: | ||
raise AccessException('You must be logged in.') | ||
return self._historyModel.undo(user) | ||
if 'datasetId' not in params: | ||
raise RestException(code=400, message='Dataset ID is missing') | ||
datasetId = ObjectId(params['datasetId']) | ||
return self._historyModel.undo(user, datasetId) | ||
|
||
@access.user | ||
@describeRoute(Description("Redo the last history entry which has been undone")) | ||
@describeRoute(Description("Redo the last history entry which has been undone") | ||
.param('datasetId', 'The dataset in which redo should be done', required=True)) | ||
def redo(self, params): | ||
user = self.getCurrentUser() | ||
if user is None: | ||
raise AccessException('You must be logged in.') | ||
self._historyModel.redo(user) | ||
if 'datasetId' not in params: | ||
raise RestException(code=400, message='Dataset ID is missing') | ||
datasetId = ObjectId(params['datasetId']) | ||
self._historyModel.redo(user, datasetId) |
Oops, something went wrong.