mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-21 20:44:18 +00:00
Resolve issue #146
This commit is contained in:
parent
315996bb17
commit
1e84796bd4
8 changed files with 36 additions and 11 deletions
|
@ -6,6 +6,7 @@ import sys
|
|||
|
||||
from .gestione import *
|
||||
from .app import app, extension_sqlalchemy
|
||||
from .database import User
|
||||
|
||||
|
||||
print(" * Swagger docs will be available at http://127.0.0.1:5000/docs")
|
||||
|
|
|
@ -2,11 +2,16 @@
|
|||
Gestione adds many fancy thingamajigs to the flask application, such as a login system and such.
|
||||
"""
|
||||
|
||||
from .database import *
|
||||
from nest_backend.database import *
|
||||
import bcrypt
|
||||
import functools
|
||||
from flask_jwt_extended import get_jwt_identity
|
||||
from flask import jsonify
|
||||
from re import sub
|
||||
|
||||
__all__ = ["authenticate", "identity", "gen_password", "find_user", "admin_or_403",
|
||||
"repository_auth", "json_request_authorizer", "json_error",
|
||||
"json_success", "error_handler", "hashtag_validator"]
|
||||
|
||||
|
||||
def authenticate(username, password):
|
||||
|
@ -110,3 +115,8 @@ def json_request_authorizer(json, serializable):
|
|||
json_keys = json.keys()
|
||||
serializable_keys = serializable.to_json().keys()
|
||||
return all(key in json_keys for key in serializable_keys)
|
||||
|
||||
|
||||
def hashtag_validator(hashtag):
|
||||
return sub(
|
||||
"([^a-z0-9_\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0100-\u024f\u0253-\u0254\u0256-\u0257\u0300-\u036f\u1e00-\u1eff\u0400-\u04ff\u0500-\u0527\u2de0-\u2dff\ua640-\ua69f\u0591-\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05d0-\u05ea\u05f0-\u05f4\ufb12-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4f\u0610-\u061a\u0620-\u065f\u066e-\u06d3\u06d5-\u06dc\u06de-\u06e8\u06ea-\u06ef\u06fa-\u06fc\u0750-\u077f\u08a2-\u08ac\u08e4-\u08fe\ufb50-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\u200c\u0e01-\u0e3a\u0e40-\u0e4e\u1100-\u11ff\u3130-\u3185\ua960-\ua97f\uac00-\ud7af\ud7b0-\ud7ff\uffa1-\uffdc\u30a1-\u30fa\u30fc-\u30fe\uff66-\uff9f\uff10-\uff19\uff21-\uff3a\uff41-\uff5a\u3041-\u3096\u3099-\u309e\u3400-\u4dbf\u4e00-\u9fff\u20000-\u2a6df\u2a700-\u2b73\u2b740-\u2b81\u2f800-\u2fa1])", "", hashtag)
|
||||
|
|
|
@ -5,3 +5,6 @@ This module imports all the routes that return something to the frontend.
|
|||
from .doa import page_doa
|
||||
from .users import *
|
||||
from .repository import *
|
||||
__all__ = ["page_alert", "page_repository_alerts", "page_repository", "page_doa",
|
||||
"page_condition", "page_repository_conditions", "page_repositories",
|
||||
"page_login", "page_user", "page_users"]
|
|
@ -3,3 +3,6 @@ from .repository import page_repository
|
|||
from .repositories import page_repositories
|
||||
from .conditions import *
|
||||
from .alerts import *
|
||||
|
||||
__all__ = ["page_condition", "page_repository_conditions", "page_repositories",
|
||||
"page_alert", "page_repository", "page_repository_alerts"]
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
from .repository_alerts import page_repository_alerts
|
||||
from .alert import page_alert
|
||||
__all__ = ["page_repository_alerts", "page_alert"]
|
|
@ -1,2 +1,3 @@
|
|||
from .repository_conditions import page_repository_conditions
|
||||
from .condition import page_condition
|
||||
__all__ = ["page_condition", "page_repository_conditions"]
|
|
@ -1,9 +1,10 @@
|
|||
from flask import request
|
||||
from flask_jwt_extended import jwt_required
|
||||
from nest_backend.gestione import repository_auth, json_error, json_success, ConditionType, Condition, Repository, \
|
||||
find_user, get_jwt_identity
|
||||
from nest_backend.database import ext as extension_sqlalchemy
|
||||
find_user, get_jwt_identity
|
||||
from nest_backend.database import ext
|
||||
from flask_cors import cross_origin
|
||||
from gestione import hashtag_validator
|
||||
|
||||
|
||||
@cross_origin()
|
||||
|
@ -43,6 +44,9 @@ def page_repository_conditions(rid):
|
|||
summary: Creates a condition and attaches it to the repository.
|
||||
security:
|
||||
- jwt: []
|
||||
parameters:
|
||||
- in: path
|
||||
schema: IntegerParameterSchema
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
|
@ -90,9 +94,10 @@ def page_repository_conditions(rid):
|
|||
|
||||
if not (content := request.json.get("content")):
|
||||
return json_error("Missing `content` parameter."), 400
|
||||
|
||||
if type_ == ConditionType.hashtag:
|
||||
content = hashtag_validator(content)
|
||||
condition = Condition(content=content, type=type_, repository_id=rid)
|
||||
extension_sqlalchemy.session.add(condition)
|
||||
extension_sqlalchemy.session.commit()
|
||||
ext.session.add(condition)
|
||||
ext.session.commit()
|
||||
|
||||
return json_success(condition.to_json()), 201
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from .users import page_users
|
||||
from .login import page_login
|
||||
from .user import page_user
|
||||
__all__ = ["page_users", "page_user", "page_login"]
|
Loading…
Reference in a new issue