Release 1.3.0

This commit is contained in:
eleanor 2020-02-18 14:41:02 -05:00
parent 9cfbd7a30a
commit 11490e6fbd
9 changed files with 30 additions and 10 deletions

View File

@ -1,8 +1,3 @@
import datetime
from dateutil.tz import tzutc
from sqlalchemy import func
from app import db
from app.model.location import Location

View File

@ -14,6 +14,7 @@ class Permission(enum.Enum):
data_admin = "Visit Data Admin"
user_detail_admin = "User Admin Data Details"
export_status = "View Export Status"
taxonomy_admin = "Visit Taxonomy Admin"
# keep user_roles and delete_user last to keep off of test user permissions
delete_user = "Delete User"

View File

@ -3,9 +3,13 @@ from flask import request
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import joinedload
from app import db, RestException
from app import auth, db, RestException
from app.model.category import Category
from app.model.study_category import StudyCategory
from app.model.resource_category import ResourceCategory
from app.schema.schema import CategorySchema, ParentCategorySchema
from app.model.role import Permission
from app.wrappers import requires_permission
class CategoryEndpoint(flask_restful.Resource):
@ -16,13 +20,28 @@ class CategoryEndpoint(flask_restful.Resource):
if category is None: raise RestException(RestException.NOT_FOUND)
return self.schema.dump(category)
@auth.login_required
@requires_permission(Permission.taxonomy_admin)
def delete(self, id):
try:
db.session.query(Category).filter(Category.id == id).delete()
cat = db.session.query(Category).filter_by(id=id).first()
self.delete_descendants(cat)
db.session.query(StudyCategory).filter_by(category_id=id).delete()
db.session.query(ResourceCategory).filter_by(category_id=id).delete()
db.session.query(Category).filter_by(id=id).delete()
db.session.commit()
except IntegrityError as error:
raise RestException(RestException.CAN_NOT_DELETE)
return
def delete_descendants(self, category):
if category and category.children:
for cat in category.children:
self.delete_descendants(cat)
db.session.query(Category).filter_by(id=cat.id).delete()
@auth.login_required
@requires_permission(Permission.taxonomy_admin)
def put(self, id):
request_data = request.get_json()
instance = db.session.query(Category).filter_by(id=id).first()
@ -30,6 +49,7 @@ class CategoryEndpoint(flask_restful.Resource):
if errors:
raise RestException(RestException.INVALID_OBJECT, details=errors)
db.session.add(updated)
db.session.commit()
return self.schema.dump(updated)
@ -44,6 +64,8 @@ class CategoryListEndpoint(flask_restful.Resource):
.all()
return self.categories_schema.dump(categories)
@auth.login_required
@requires_permission(Permission.taxonomy_admin)
def post(self):
request_data = request.get_json()
new_cat, errors = self.category_schema.load(request_data)

View File

@ -7,6 +7,7 @@ from marshmallow import ValidationError
from app import RestException, db, elastic_index
from app.model.study import Study
from app.model.study_category import StudyCategory
from app.model.study_investigator import StudyInvestigator
from app.schema.schema import StudySchema
@ -25,6 +26,7 @@ class StudyEndpoint(flask_restful.Resource):
if study is not None:
elastic_index.remove_document(study, 'Study')
db.session.query(StudyInvestigator).filter_by(study_id=id).delete()
db.session.query(StudyCategory).filter_by(study_id=id).delete()
db.session.query(Study).filter_by(id=id).delete()
db.session.commit()

View File

@ -27,6 +27,6 @@
<body>
<app-root></app-root>
<script src="runtime-es2015.858f8dd898b75fe86926.js" type="module"></script><script src="polyfills-es2015.696ad2b135b52dd9855f.js" type="module"></script><script src="runtime-es5.741402d1d47331ce975c.js" nomodule></script><script src="polyfills-es5.6ba1fc6238374eb32f77.js" nomodule></script><script src="main-es2015.18ac9c6a93acd7e94b65.js" type="module"></script><script src="main-es5.0f1b8703b66b9993fa83.js" nomodule></script></body>
<script src="runtime-es2015.858f8dd898b75fe86926.js" type="module"></script><script src="polyfills-es2015.696ad2b135b52dd9855f.js" type="module"></script><script src="runtime-es5.741402d1d47331ce975c.js" nomodule></script><script src="polyfills-es5.6ba1fc6238374eb32f77.js" nomodule></script><script src="main-es2015.e5c9f44f2024e9ec9260.js" type="module"></script><script src="main-es5.05d7c99c43ef2675caee.js" nomodule></script></body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long