Skip to content

Commit

Permalink
Reject empty names for dashboards (re getredash#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Short committed Jul 25, 2018
1 parent 31358be commit d4813e4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions client/app/components/dashboards/edit-dashboard-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h4 class="modal-title">New Dashboard</h4>
</div>
<div class="modal-body" ng-if="$ctrl.policy.isCreateDashboardEnabled()">
<p>
<input type="text" class="form-control" placeholder="Dashboard Name" ng-model="$ctrl.dashboard.name" autofocus ng-keyup="$event.keyCode === 13 && $ctrl.saveDashboard()">
<input type="text" class="form-control" placeholder="Dashboard Name" ng-model="$ctrl.dashboard.name" autofocus ng-keyup="$event.keyCode === 13 && $ctrl.saveDashboard()" required>
</p>
</div>
<div class="modal-footer" ng-if="$ctrl.policy.isCreateDashboardEnabled()">
Expand All @@ -14,4 +14,4 @@ <h4 class="modal-title">New Dashboard</h4>

<div class="modal-body" ng-if="!$ctrl.policy.isCreateDashboardEnabled()">
<edit-dashboard-dialog-disabled></edit-dashboard-dialog-disabled>
</div>
</div>
3 changes: 3 additions & 0 deletions redash/handlers/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from redash.permissions import (can_modify, require_admin_or_owner,
require_object_modify_permission,
require_permission)
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import StaleDataError


Expand Down Expand Up @@ -146,6 +147,8 @@ def post(self, dashboard_slug):
models.db.session.commit()
except StaleDataError:
abort(409)
except IntegrityError:
abort(400)

result = serialize_dashboard(dashboard, with_widgets=True, user=self.current_user)
return result
Expand Down
2 changes: 1 addition & 1 deletion redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ class Dashboard(ChangeTrackingMixin, TimestampMixin, BelongsToOrgMixin, db.Model
org_id = Column(db.Integer, db.ForeignKey("organizations.id"))
org = db.relationship(Organization, backref="dashboards")
slug = Column(db.String(140), index=True, default=generate_slug)
name = Column(db.String(100))
name = Column(db.String(100), db.CheckConstraint("name<>''", name="dashboard_name_c"))
user_id = Column(db.Integer, db.ForeignKey("users.id"))
user = db.relationship(User)
# layout is no longer used, but kept so we know how to render old dashboards.
Expand Down

0 comments on commit d4813e4

Please sign in to comment.