-
Notifications
You must be signed in to change notification settings - Fork 113
Add per-user favorite support for charts and dashboards, so starring … #1437
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fbdb5a2
Add per-user favorite support for charts and dashboards, so starring …
NaveenCode c5f40c4
Refactor favorite functionality: consolidate chart and dashboard favo…
NaveenCode cfb57b6
Merge branch 'main' of https://github.com/DalgoT4D/DDP_backend into f…
NaveenCode 734d73a
Add permission checks for favoriting and unfavoriting dashboards
NaveenCode 4a74941
Merge branch 'main' of https://github.com/DalgoT4D/DDP_backend into f…
himanshudube97 b176daa
Implement favorite removal on chart and dashboard deletion
NaveenCode 8e7be74
Merge branch 'feature/chart-dashboard-favorites' of https://github.co…
NaveenCode bc6e050
Refactor dashboard and chart deletion to use atomic transactions and …
NaveenCode ecdc8b8
updates
himanshudube97 8a30c6b
Merge branch 'main' of https://github.com/DalgoT4D/DDP_backend into f…
NaveenCode 8f389b6
Merge branch 'feature/chart-dashboard-favorites' of https://github.co…
NaveenCode 514ee0e
Implement favoriting functionality for charts and dashboards with acc…
NaveenCode f4984d2
Merge branch 'main' of https://github.com/DalgoT4D/DDP_backend into f…
NaveenCode 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 hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| # Generated by Django 4.2 on 2026-08-18 06:33 | ||
|
|
||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("ddpui", "0176_trialsignup"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="Favorite", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.BigAutoField( | ||
| auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
| ), | ||
| ), | ||
| ( | ||
| "resource_type", | ||
| models.CharField( | ||
| choices=[("chart", "CHART"), ("dashboard", "DASHBOARD")], max_length=20 | ||
| ), | ||
| ), | ||
| ("resource_id", models.BigIntegerField()), | ||
| ("created_at", models.DateTimeField(auto_now_add=True)), | ||
| ( | ||
| "org_user", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="favorites", | ||
| to="ddpui.orguser", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "db_table": "favorite", | ||
| }, | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name="favorite", | ||
| index=models.Index( | ||
| fields=["resource_type", "resource_id"], name="favorite_resourc_ad1413_idx" | ||
| ), | ||
| ), | ||
| migrations.AddConstraint( | ||
| model_name="favorite", | ||
| constraint=models.UniqueConstraint( | ||
| fields=("org_user", "resource_type", "resource_id"), name="unique_favorite" | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or 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,46 @@ | ||
| """Shared favorite model for charts, dashboards, and other favoritable resources. | ||
|
|
||
| Mirrors Apache Superset's own `favstar` table design (superset/models/core.py): | ||
| one shared table keyed by (user, resource_type, resource_id) instead of a | ||
| separate table per resource type. | ||
| """ | ||
|
|
||
| from enum import Enum | ||
| from django.db import models | ||
| from ddpui.models.org_user import OrgUser | ||
|
|
||
|
|
||
| class FavoriteResourceType(str, Enum): | ||
| """Resource types that can be favorited""" | ||
|
|
||
| CHART = "chart" | ||
| DASHBOARD = "dashboard" | ||
|
|
||
| @classmethod | ||
| def choices(cls): | ||
| """django model definition needs an iterable for `choices`""" | ||
| return [(key.value, key.name) for key in cls] | ||
|
|
||
|
|
||
| class Favorite(models.Model): | ||
| """Tracks which org users have favorited which resources. Favoriting is | ||
| personal — one user's favorite has no effect on any other user.""" | ||
|
|
||
| org_user = models.ForeignKey(OrgUser, on_delete=models.CASCADE, related_name="favorites") | ||
| resource_type = models.CharField(max_length=20, choices=FavoriteResourceType.choices()) | ||
| resource_id = models.BigIntegerField() | ||
| created_at = models.DateTimeField(auto_now_add=True) | ||
|
|
||
| class Meta: | ||
| db_table = "favorite" | ||
| constraints = [ | ||
| models.UniqueConstraint( | ||
| fields=["org_user", "resource_type", "resource_id"], name="unique_favorite" | ||
| ) | ||
| ] | ||
| indexes = [ | ||
| models.Index(fields=["resource_type", "resource_id"]), | ||
| ] | ||
|
|
||
| def __str__(self): | ||
| return f"{self.org_user.user.email} favorited {self.resource_type} {self.resource_id}" | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
If i delete a chart then it won't delete the rows in ths table right ? Same with the dashboard too.
Is this the correct design choice ?
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.
Correct, it should be like what you are suggesting. Updated, thanks
Now, when deleting the chart/dashboard, entry for that chart/dashboard will also be removed from the favorite table