Backend only tagging system (#6823)

This PR introduces the backend changes for a tagging system for Superset, allowing dashboards, charts and queries to be tagged. It also allows searching for a given tag, and will be the basis for a new landing page (see #5327).

# Implicit tags
Dashboard, chart and (saved) queries have implicit tags related to their owners, types and favorites. For example, all objects owned by the admin have the tag `owner:1`. All charts have the tag `type:chart`. Objects favorited by the admin have the tag `favorited_by:1`.

These tags are automatically added by a migration script, and kept in sync through SQLAlchemy event listeners. They are currently not surfaced to the user, but can be searched for. For example, it's possible to search for `owner:1` in the welcome page to see all objects owned by the admin, or even search for `owner:{{ current_user_id() }}`.

(cherry picked from commit 8041b63af6)
This commit is contained in:
Beto Dealmeida
2019-02-06 13:42:42 -08:00
committed by Christine Chambers
parent 1ddacc42d0
commit f24efa7250
6 changed files with 694 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ from sqlalchemy.orm import backref, relationship
from superset import security_manager
from superset.models.helpers import AuditMixinNullable, ExtraJSONMixin
from superset.models.tags import QueryUpdater
from superset.utils.core import QueryStatus, user_label
@@ -173,3 +174,12 @@ class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin):
@property
def sqlalchemy_uri(self):
return self.database.sqlalchemy_uri
def url(self):
return '/superset/sqllab?savedQueryId={0}'.format(self.id)
# events for updating tags
sqla.event.listen(SavedQuery, 'after_insert', QueryUpdater.after_insert)
sqla.event.listen(SavedQuery, 'after_update', QueryUpdater.after_update)
sqla.event.listen(SavedQuery, 'after_delete', QueryUpdater.after_delete)