Browse Source

Fixed validation for adding api keys, added unique index for api key name + account_id

Torkel Ödegaard 11 years ago
parent
commit
23bbc5160e
2 changed files with 5 additions and 2 deletions
  1. 2 2
      pkg/models/apikey.go
  2. 3 0
      pkg/services/sqlstore/migrations.go

+ 2 - 2
pkg/models/apikey.go

@@ -20,8 +20,8 @@ type ApiKey struct {
 // ---------------------
 // ---------------------
 // COMMANDS
 // COMMANDS
 type AddApiKeyCommand struct {
 type AddApiKeyCommand struct {
-	Name      string   `json:"name" binding:"required"`
-	Role      RoleType `json:"role" binding:"required"`
+	Name      string   `json:"name" binding:"Required"`
+	Role      RoleType `json:"role" binding:"Required"`
 	AccountId int64    `json:"-"`
 	AccountId int64    `json:"-"`
 	Key       string   `json:"-"`
 	Key       string   `json:"-"`
 
 

+ 3 - 0
pkg/services/sqlstore/migrations.go

@@ -172,4 +172,7 @@ func addApiKeyMigrations(mg *Migrator) {
 
 
 	mg.AddMigration("add index api_key.key", new(AddIndexMigration).
 	mg.AddMigration("add index api_key.key", new(AddIndexMigration).
 		Table("api_key").Columns("key").Unique())
 		Table("api_key").Columns("key").Unique())
+
+	mg.AddMigration("add index api_key.account_id_name", new(AddIndexMigration).
+		Table("api_key").Columns("account_id", "name").Unique())
 }
 }