1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 06:24:19 +00:00

Fixed issues

This commit is contained in:
Lorenzo Balugani 2021-05-11 18:45:40 +02:00
parent da4c5e1334
commit 390ee441c0
9 changed files with 21 additions and 21 deletions

View file

@ -15,8 +15,8 @@ class Alert(ext.Model):
repository_id = ext.Column(ext.Integer, ext.ForeignKey("repository.id", ondelete="CASCADE"), nullable=False) repository_id = ext.Column(ext.Integer, ext.ForeignKey("repository.id", ondelete="CASCADE"), nullable=False)
# Relationships # Relationships
repository = ext.relationship("Repository", back_populates="alerts") repository = ext.relationship("Repository", back_populates="alerts")
notifications = ext.relationship("Notification", back_populates="alert", cascade="all, delete") notifications = ext.relationship("Notification", back_populates="alert")
operations = ext.relationship("BoolOperation", back_populates="alert", cascade="all, delete") operations = ext.relationship("BoolOperation", back_populates="alert")
def to_json(self): def to_json(self):
return { return {

View file

@ -12,12 +12,12 @@ class BoolOperation(ext.Model):
id = ext.Column(ext.Integer, primary_key=True) id = ext.Column(ext.Integer, primary_key=True)
operation = ext.Column(ext.Enum(OperationType), nullable=False) operation = ext.Column(ext.Enum(OperationType), nullable=False)
isRoot = ext.Column(ext.Boolean, default=False, nullable=False) is_root = ext.Column(ext.Boolean, default=False, nullable=False)
# Foreign Keys # Foreign Keys
condition_id = ext.Column(ext.Integer, ext.ForeignKey("condition.id")) condition_id = ext.Column(ext.Integer, ext.ForeignKey("condition.id"))
node_1_id = ext.Column(ext.Integer, ext.ForeignKey("bool_operation.id", ondelete="SET NULL")) node_1_id = ext.Column(ext.Integer, ext.ForeignKey("bool_operation.id", ondelete="SET NULL"))
node_2_id = ext.Column(ext.Integer, ext.ForeignKey("bool_operation.id", ondelete="SET NULL")) node_2_id = ext.Column(ext.Integer, ext.ForeignKey("bool_operation.id", ondelete="SET NULL"))
alert_id = ext.Column(ext.Integer, ext.ForeignKey("alert.id")) alert_id = ext.Column(ext.Integer, ext.ForeignKey("alert.id", ondelete="CASCADE"))
# Relationships # Relationships
condition = ext.relationship("Condition", back_populates="operations") condition = ext.relationship("Condition", back_populates="operations")
node_1 = ext.relationship("BoolOperation", primaryjoin=("bool_operation.c.node_1_id==bool_operation.c.id"), node_1 = ext.relationship("BoolOperation", primaryjoin=("bool_operation.c.node_1_id==bool_operation.c.id"),

View file

@ -7,7 +7,7 @@ from ..base import ext
class Composed(ext.Model): class Composed(ext.Model):
__tablename__ = "composed" __tablename__ = "composed"
rid = ext.Column(ext.Integer, ext.ForeignKey("repository.id"), primary_key=True) rid = ext.Column(ext.Integer, ext.ForeignKey("repository.id", ondelete="CASCADE"), primary_key=True)
snowflake = ext.Column(ext.String, ext.ForeignKey("tweet.snowflake"), primary_key=True) snowflake = ext.Column(ext.String, ext.ForeignKey("tweet.snowflake"), primary_key=True)
# Relationships # Relationships
repository = ext.relationship("Repository", back_populates="tweets") repository = ext.relationship("Repository", back_populates="tweets")

View file

@ -9,12 +9,12 @@ from .Enums import ConditionType
class Condition(ext.Model): class Condition(ext.Model):
__tablename__ = "condition" __tablename__ = "condition"
id = ext.Column(ext.Integer, primary_key=True) id = ext.Column(ext.Integer, primary_key=True)
type = ext.Column(ext.Enum(ConditionType), nullable=False) type = ext.Column(ext.Enum(ConditionType), nullable=False, default=ConditionType.hashtag)
content = ext.Column(ext.String, nullable=False) content = ext.Column(ext.String, nullable=False)
# FK # FK
repository_id = ext.Column(ext.Integer, ext.ForeignKey("repository.id", ondelete="CASCADE")) repository_id = ext.Column(ext.Integer, ext.ForeignKey("repository.id", ondelete="CASCADE"))
# Relationships # Relationships
repository = ext.relationship("Repository", back_populates="conditions", cascade="all, delete") repository = ext.relationship("Repository", back_populates="conditions")
tweets = ext.relationship("Contains", back_populates="condition") tweets = ext.relationship("Contains", back_populates="condition")
operations = ext.relationship("BoolOperation", back_populates="condition") operations = ext.relationship("BoolOperation", back_populates="condition")

View file

@ -7,8 +7,8 @@ from ..base import ext
class Contains(ext.Model): class Contains(ext.Model):
__tablename__ = "contains" __tablename__ = "contains"
cid = ext.Column(ext.Integer, ext.ForeignKey("condition.id"), primary_key=True) cid = ext.Column(ext.Integer, ext.ForeignKey("condition.id", ondelete="CASCADE"), primary_key=True)
snowflake = ext.Column(ext.String, ext.ForeignKey("tweet.snowflake"), primary_key=True) snowflake = ext.Column(ext.String, ext.ForeignKey("tweet.snowflake", ondelete="CASCADE"), primary_key=True)
# Relationships # Relationships
condition = ext.relationship("Condition", back_populates="tweets") condition = ext.relationship("Condition", back_populates="tweets")
tweet = ext.relationship("Tweet", back_populates="conditions") tweet = ext.relationship("Tweet", back_populates="conditions")

View file

@ -10,7 +10,7 @@ class Notification(ext.Model):
id = ext.Column(ext.Integer, primary_key=True) id = ext.Column(ext.Integer, primary_key=True)
ora = ext.Column(ext.DateTime, nullable=False) ora = ext.Column(ext.DateTime, nullable=False)
# Foreign Key # Foreign Key
alert_id = ext.Column(ext.Integer, ext.ForeignKey("alert.id"), nullable=False) alert_id = ext.Column(ext.Integer, ext.ForeignKey("alert.id", ondelete="CASCADE"), nullable=False)
# Relationships # Relationships
alert = ext.relationship("Alert", back_populates="notifications") alert = ext.relationship("Alert", back_populates="notifications")

View file

@ -22,9 +22,9 @@ class Repository(ext.Model):
# Relationships # Relationships
owner = ext.relationship("User", back_populates="owner_of") owner = ext.relationship("User", back_populates="owner_of")
authorizations = ext.relationship("Authorization", back_populates="repository", cascade="all, delete") authorizations = ext.relationship("Authorization", back_populates="repository")
tweets = ext.relationship("Composed", back_populates="repository", cascade="all, delete") tweets = ext.relationship("Composed", back_populates="repository")
alerts = ext.relationship("Alert", back_populates="repository", cascade="all, delete") alerts = ext.relationship("Alert", back_populates="repository")
conditions = ext.relationship("Condition", back_populates="repository") conditions = ext.relationship("Condition", back_populates="repository")
def to_json(self): def to_json(self):

View file

@ -191,9 +191,10 @@ def page_repository(rid):
return json_error("Missing one or more parameters in repository json."), 400 return json_error("Missing one or more parameters in repository json."), 400
# Users will be tolerated if they change parameters they're not supposed to touch. We'll ignore them for now. # Users will be tolerated if they change parameters they're not supposed to touch. We'll ignore them for now.
try: try:
repository.evaluation_mode = request.json['evaluation_mode'] evaluation_mode = ConditionMode(request.json['evaluation_mode'])
except KeyError: except KeyError:
return json_error("Unknown `type` specified."), 400 return json_error("Unknown `type` specified."), 400
repository.evaluation_mode = evaluation_mode
repository.name = request.json['name'] repository.name = request.json['name']
repository.is_active = request.json['is_active'] repository.is_active = request.json['is_active']
ids = [c['id'] for c in request.json['conditions'] if c['id']] ids = [c['id'] for c in request.json['conditions'] if c['id']]
@ -205,11 +206,10 @@ def page_repository(rid):
# Create brand new conditions # Create brand new conditions
for c in request.json['conditions']: for c in request.json['conditions']:
if not c['id']: if not c['id']:
if (type_ := c['type']) is not None: try:
try: type_ = ConditionType(c['type'])
type_ = ConditionType(type_) except KeyError:
except KeyError: return json_error("Unknown `type` specified."), 400
return json_error("Unknown `type` specified."), 400
ext.session.add(Condition(type=type_, content=c['content'], repository_id=rid)) ext.session.add(Condition(type=type_, content=c['content'], repository_id=rid))
ext.session.commit() ext.session.commit()
return json_success(repository.to_json()), 200 return json_success(repository.to_json()), 200

View file

@ -133,7 +133,7 @@ def page_user(email):
except Exception: except Exception:
ext.session.rollback() ext.session.rollback()
return json_error("Could not delete the user."), 500 return json_error("Could not delete the user."), 500
return json_success("The user has been deleted.") return json_success("The user has been deleted."), 200
elif request.method == "PATCH": elif request.method == "PATCH":
if not email == user.email and not user.isAdmin: if not email == user.email and not user.isAdmin:
return json_error("Thou art not authorized."), 403 return json_error("Thou art not authorized."), 403
@ -143,4 +143,4 @@ def page_user(email):
if request.json.get("password"): if request.json.get("password"):
target.password = gen_password(request.json.get("password")) target.password = gen_password(request.json.get("password"))
ext.session.commit() ext.session.commit()
return json_success(target.to_json()) return json_success(target.to_json()), 200