Skip to content
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

improvement(views): Highlights View widget #499

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
130 changes: 130 additions & 0 deletions argus/backend/controller/views_widgets/highlights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from dataclasses import dataclass, asdict
from datetime import datetime, UTC

from flask import Blueprint, request, g

from argus.backend.service.user import api_login_required
from argus.backend.service.views_widgets.highlights import (
HighlightCreate,
HighlightsService,
HighlightArchive,
HighlightUpdate,
HighlightSetAssignee,
HighlightSetCompleted,
CommentUpdate,
CommentDelete,
CommentCreate,
)
from argus.backend.util.common import get_payload

bp = Blueprint("view_widgets", __name__, url_prefix="/widgets")


@bp.route("/highlights/create", methods=["POST"])
@api_login_required
def create_highlight():
creator_id = g.user.id
payload = HighlightCreate(**get_payload(request))
service = HighlightsService()
highlight = service.create(creator_id, payload)
return {"status": "ok", "response": asdict(highlight)}


@bp.route("/highlights", methods=["GET"])
@api_login_required
def get_highlights():
view_id = request.args.get("view_id")
service = HighlightsService()
highlights, action_items = service.get_highlights(view_id)
return {
"status": "ok",
"response": {
"highlights": [asdict(h) for h in highlights],
"action_items": [asdict(a) for a in action_items],
},
}


@bp.route("/highlights/archive", methods=["POST"])
@api_login_required
def archive_highlight():
payload = HighlightArchive(**get_payload(request))
service = HighlightsService()
service.archive_highlight(payload.view_id, payload.created_at, datetime.now(UTC))
return {"status": "ok"}


@bp.route("/highlights/unarchive", methods=["POST"])
@api_login_required
def unarchive_highlight():
payload = HighlightArchive(**get_payload(request))
service = HighlightsService()
service.archive_highlight(payload.view_id, payload.created_at, datetime.fromtimestamp(0, tz=UTC))
return {"status": "ok"}


@bp.route("/highlights/update", methods=["POST"])
@api_login_required
def update_highlight():
payload = HighlightUpdate(**get_payload(request))
service = HighlightsService()
updated_highlight = service.update_highlight(g.user.id, payload)
return {"status": "ok", "response": asdict(updated_highlight)}


@bp.route("/highlights/set_assignee", methods=["POST"])
@api_login_required
def set_assignee():
payload = HighlightSetAssignee(**get_payload(request))
service = HighlightsService()
updated_action_item = service.set_assignee(payload)
return {"status": "ok", "response": asdict(updated_action_item)}


@bp.route("/highlights/set_completed", methods=["POST"])
@api_login_required
def set_completed():
payload = HighlightSetCompleted(**get_payload(request))
service = HighlightsService()
updated_action_item = service.set_completed(payload)
return {"status": "ok", "response": asdict(updated_action_item)}


@bp.route("/highlights/comments/create", methods=["POST"])
@api_login_required
def create_comment():
creator_id = g.user.id
payload = CommentCreate(**get_payload(request))
service = HighlightsService()
comment = service.create_comment(creator_id, payload)
return {"status": "ok", "response": asdict(comment)}


@bp.route("/highlights/comments/update", methods=["POST"])
@api_login_required
def update_comment():
user_id = g.user.id
payload = CommentUpdate(**get_payload(request))
service = HighlightsService()
updated_comment = service.update_comment(user_id, payload)
return {"status": "ok", "response": asdict(updated_comment)}


@bp.route("/highlights/comments/delete", methods=["POST"])
@api_login_required
def delete_comment():
user_id = g.user.id
payload = CommentDelete(**get_payload(request))
service = HighlightsService()
service.delete_comment(user_id, payload)
return {"status": "ok"}


@bp.route("/highlights/comments", methods=["GET"])
@api_login_required
def get_comments():
view_id = request.args.get("view_id")
highlight_created_at = float(request.args.get("created_at"))
service = HighlightsService()
comments = service.get_comments(view_id, highlight_created_at)
return {"status": "ok", "response": [asdict(c) for c in comments]}
22 changes: 22 additions & 0 deletions argus/backend/models/view_widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime, UTC

from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model


class WidgetHighlights(Model):
view_id = columns.UUID(partition_key=True, required=True)
created_at = columns.DateTime(primary_key=True, clustering_order="DESC")
archived_at = columns.DateTime(default=datetime.fromtimestamp(0, tz=UTC))
creator_id = columns.UUID()
assignee_id = columns.UUID()
content = columns.Text()
completed = columns.Boolean(default=lambda: None) # None means it's highlight, not an action item
comments_count = columns.TinyInt()

class WidgetComment(Model):
view_id = columns.UUID(partition_key=True, required=True)
highlight_at = columns.DateTime(partition_key=True, required=True) # reference to WidgetHighlights.created_at
created_at = columns.DateTime(primary_key=True)
creator_id = columns.UUID()
content = columns.Text()
3 changes: 3 additions & 0 deletions argus/backend/models/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from argus.backend.models.plan import ArgusReleasePlan
from argus.backend.models.result import ArgusGenericResultMetadata, ArgusGenericResultData, ArgusBestResultData
from argus.backend.models.view_widgets import WidgetHighlights, WidgetComment


def uuid_now():
Expand Down Expand Up @@ -385,6 +386,8 @@ class WebFileStorage(Model):
ArgusGenericResultData,
ArgusBestResultData,
ArgusReleasePlan,
WidgetHighlights,
WidgetComment,
]

USED_TYPES: list[UserType] = [
Expand Down
Empty file.
Loading
Loading