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 May 5, 2017
1 parent 0ad235a commit ebebbe2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/app/pages/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">Edit: {{$ctrl.dashboard.name}}</h4>
</div>
<div class="modal-body">
<p>
<input type="text" class="form-control" placeholder="Dashboard Name" ng-model="$ctrl.dashboard.name">
<input type="text" class="form-control" placeholder="Dashboard Name" ng-model="$ctrl.dashboard.name" required>
</p>

<div gridster="$ctrl.gridsterOptions" ng-if="$ctrl.items | notEmpty">
Expand Down
4 changes: 3 additions & 1 deletion redash/handlers/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from flask import request, url_for
from flask_restful import abort
from funcy import distinct, project, take
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import StaleDataError

from redash import models, serializers
Expand Down Expand Up @@ -148,7 +149,8 @@ def post(self, dashboard_slug):
models.db.session.commit()
except StaleDataError:
abort(409)

except IntegrityError:
abort(400)
result = dashboard.to_dict(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 @@ -1162,7 +1162,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)
# TODO: The layout should dynamically be built from position and size information on each widget.
Expand Down

0 comments on commit ebebbe2

Please sign in to comment.