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 Dec 12, 2017
1 parent 6d499c2 commit f50acc2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
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" autofocus>
<input type="text" class="form-control" placeholder="Dashboard Name" ng-model="$ctrl.dashboard.name" autofocus required>
</p>

<p ng-if="$ctrl.dashboard.id">
Expand Down
3 changes: 3 additions & 0 deletions redash/handlers/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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 @@ -154,6 +155,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 @@ -1264,7 +1264,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 f50acc2

Please sign in to comment.