add org_id to favorites

This commit is contained in:
Arik Fraimovich 2018-05-10 12:51:11 +03:00
parent bcf49a700b
commit 9feb7773ce
3 changed files with 29 additions and 2 deletions

View File

@ -0,0 +1,26 @@
"""add_org_id_to_favorites
Revision ID: e7004224f284
Revises: d4c798575877
Create Date: 2018-05-10 09:46:31.169938
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'e7004224f284'
down_revision = 'd4c798575877'
branch_labels = None
depends_on = None
def upgrade():
op.add_column('favorites', sa.Column('org_id', sa.Integer(), nullable=True))
op.create_foreign_key(None, 'favorites', 'organizations', ['org_id'], ['id'])
def downgrade():
op.drop_constraint(None, 'favorites', type_='foreignkey')
op.drop_column('favorites', 'org_id')

View File

@ -14,7 +14,7 @@ class QueryFavoriteResource(BaseResource):
query = get_object_or_404(models.Query.get_by_id_and_org, query_id, self.current_org)
require_access(query.groups, self.current_user, view_only)
fav = models.Favorite(object=query, user=self.current_user)
fav = models.Favorite(org_id=self.current_org.id, object=query, user=self.current_user)
models.db.session.add(fav)
models.db.session.commit()
@ -35,7 +35,7 @@ class DashboardFavoriteListResource(BaseResource):
class DashboardFavoriteResource(BaseResource):
def post(self, object_id):
dashboard = get_object_or_404(models.Dashboard.get_by_slug_and_org, object_id, self.current_org)
fav = models.Favorite(object=dashboard, user=self.current_user)
fav = models.Favorite(org_id=self.current_org.id, object=dashboard, user=self.current_user)
models.db.session.add(fav)
models.db.session.commit()

View File

@ -1087,6 +1087,7 @@ class Favorite(TimestampMixin, db.Model):
__tablename__ = "favorites"
id = Column(db.Integer, primary_key=True)
org_id = Column(db.Integer, db.ForeignKey("organizations.id"))
object_type = Column(db.Unicode(255))
object_id = Column(db.Integer)