forked from vikunja/vikunja
Compare commits
3 Commits
master
...
feature/te
Author | SHA1 | Date | |
---|---|---|---|
37e4aa9c4f | |||
b7918a694e | |||
6627c074bd |
@ -215,7 +215,7 @@ Sorry for some of them being in German, I'll tranlate them at some point.
|
||||
* [x] Fix lint errors
|
||||
* [x] Add settings for max open/idle connections and max connection lifetime
|
||||
* [x] Reminders should use an extra table so we can make reverse lookups aka "give me all tasks with reminders in this period" which we'll need for things like email reminders notifications
|
||||
* [ ] Teams and users should also have uuids (for users these can be the username)
|
||||
* [x] Teams and users should also have uuids (for users these can be the username)
|
||||
* [ ] When giving a team or user access to a list/namespace, they should be reffered to by uuid, not numeric id
|
||||
* [ ] Adding users to a team should also use uuid
|
||||
* [ ] Check if the team/user really exist before updating them on lists/namespaces
|
||||
|
71
pkg/migration/20190525101422.go
Normal file
71
pkg/migration/20190525101422.go
Normal file
@ -0,0 +1,71 @@
|
||||
// Vikunja is a todo-list application to facilitate your life.
|
||||
// Copyright 2019 Vikunja and contributors. All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package migration
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/utils"
|
||||
"github.com/go-xorm/xorm"
|
||||
"src.techknowlogick.com/xormigrate"
|
||||
)
|
||||
|
||||
type team20190525101422 struct {
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk"`
|
||||
UID string `xorm:"varchar(32) null"`
|
||||
Name string `xorm:"varchar(250) not null"`
|
||||
Description string `xorm:"varchar(250)"`
|
||||
CreatedByID int64 `xorm:"int(11) not null INDEX"`
|
||||
Created int64 `xorm:"created"`
|
||||
Updated int64 `xorm:"updated"`
|
||||
}
|
||||
|
||||
// TableName returns a pretty table name
|
||||
func (team20190525101422) TableName() string {
|
||||
return "teams"
|
||||
}
|
||||
|
||||
func init() {
|
||||
migrations = append(migrations, &xormigrate.Migration{
|
||||
ID: "20190525101422",
|
||||
Description: "Add uids to teams",
|
||||
Migrate: func(tx *xorm.Engine) error {
|
||||
err := tx.Sync2(team20190525101422{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// get all current teams and generate a random uid for them
|
||||
var allTeams []*team20190525101422
|
||||
err = tx.Find(&allTeams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, t := range allTeams {
|
||||
t.UID = utils.MakeRandomString(32)
|
||||
_, err = tx.Where("id = ?", t.ID).Update(t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Rollback: func(tx *xorm.Engine) error {
|
||||
return dropTableColum(tx, "teams", "uid")
|
||||
},
|
||||
})
|
||||
}
|
@ -22,6 +22,8 @@ import "code.vikunja.io/web"
|
||||
type Team struct {
|
||||
// The unique, numeric id of this team.
|
||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"team"`
|
||||
// The unique uuid for this team. Used to give a team access to things.
|
||||
UID string `xorm:"varchar(32) null" json:"uid"`
|
||||
// The name of this team.
|
||||
Name string `xorm:"varchar(250) not null" json:"name" valid:"required,runelength(5|250)" minLength:"5" maxLength:"250"`
|
||||
// The team's description.
|
||||
|
@ -18,6 +18,7 @@ package models
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/metrics"
|
||||
"code.vikunja.io/api/pkg/utils"
|
||||
"code.vikunja.io/web"
|
||||
)
|
||||
|
||||
@ -46,6 +47,7 @@ func (t *Team) Create(a web.Auth) (err error) {
|
||||
|
||||
t.CreatedByID = doer.ID
|
||||
t.CreatedBy = *doer
|
||||
t.UID = utils.MakeRandomString(32)
|
||||
|
||||
_, err = x.Insert(t)
|
||||
if err != nil {
|
||||
|
@ -38,6 +38,8 @@ func TestTeam_Create(t *testing.T) {
|
||||
assert.True(t, allowed)
|
||||
err = dummyteam.Create(&doer)
|
||||
assert.NoError(t, err)
|
||||
// Check the uid was created successfully
|
||||
assert.NotEqual(t, "", dummyteam.UID)
|
||||
|
||||
// Check if it was inserted and we're admin
|
||||
tm := Team{ID: dummyteam.ID}
|
||||
|
Loading…
x
Reference in New Issue
Block a user