-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mongo filetypes #966
Open
davidfarkas
wants to merge
16
commits into
master
Choose a base branch
from
mongo-filetypes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mongo filetypes #966
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0e68c71
Add regexs to indentify file types, store these in mongodb, load them…
davidfarkas93 f2af51a
Remove unused import
davidfarkas93 5cdd129
Add file type handler to manage file type through the api (add/replac…
davidfarkas93 466ca1b
New integration test for the file types handlers
davidfarkas93 0e1ffa0
Add new try_update_one db util method, and fix the dup key exists err…
davidfarkas93 206d69e
Fix typo in config.py
davidfarkas93 b043b86
Add some documentation, and increase code coverage
davidfarkas93 ad9a703
Update permission checking, schema validating, remove JS query
davidfarkas93 dd7e4ca
Load mongo filetypes via the bootstrap script
davidfarkas93 0cdbf5d
Update file type tests
davidfarkas93 6cf6e2c
Refine the file type regular expressions, use re.search instead of ma…
davidfarkas93 c5c6b42
Update abao load fixture script to load the necessary file types too
davidfarkas93 82684f2
Add stylized file types
gsfr d79658a
Refine file types
gsfr 3af4e58
Add db upgrade for filetypes
nagem 0cc3c28
Add one more case change
gsfr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import re | ||
|
||
from .. import config | ||
from ..auth import require_admin, require_login | ||
from ..validators import validate_data, InputValidationException | ||
from ..web import base | ||
|
||
|
||
class FileType(base.RequestHandler): | ||
|
||
@require_login | ||
def get(self): | ||
"""Get file types""" | ||
return config.db.filetypes.find() | ||
|
||
@require_admin | ||
def post(self): | ||
""" | ||
Insert or replace a file type. Required fields: '_id' and 'regex' where the '_id' is the unique name of | ||
the file type and 'regex' is a regular expression which is used to figure out the file type from the file name. | ||
""" | ||
payload = self.request.json_body | ||
validate_data(payload, 'filetype.json', 'input', 'POST') | ||
try: | ||
re.compile(payload['regex']) | ||
except re.error: | ||
raise InputValidationException('Invalid regular expression') | ||
result = config.db.filetypes.replace_one({'_id': payload['_id']}, payload, upsert=True) | ||
if result.acknowledged: | ||
_id = result.upserted_id if result.upserted_id else payload['_id'] | ||
return {'_id': _id} | ||
else: | ||
self.abort(404, 'File type {} not updated'.format(payload['_id'])) | ||
|
||
@require_admin | ||
def delete(self, _id): | ||
"""Delete a file type""" | ||
result = config.db.filetypes.delete_one({'_id': _id}) | ||
if result.deleted_count: | ||
return {'deleted': result.deleted_count} | ||
else: | ||
self.abort(404, 'File type {} not removed'.format(_id)) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same regex as
fname
above, does it need to be separate?