From 0b8e90e39b9a0b56db2cdd1241e377f10af6b8bf Mon Sep 17 00:00:00 2001 From: Nicolas Gourdon Date: Sun, 28 Apr 2019 10:06:26 +0200 Subject: [PATCH] Add field IsAllRepositories to team --- models/migrations/migrations.go | 2 ++ models/migrations/v85.go | 25 +++++++++++++++++++++++++ models/org.go | 11 ++++++----- models/org_team.go | 23 ++++++++++++----------- 4 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 models/migrations/v85.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 62c41fb906..e5f08365fc 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -223,6 +223,8 @@ var migrations = []Migration{ NewMigration("add uploader id for table attachment", addUploaderIDForAttachment), // v84 -> v85 NewMigration("add table to store original imported gpg keys", addGPGKeyImport), + // v85 -> v86 + NewMigration("add is_all_repositories to teams", addTeamIsAllRepositories), } // Migrate database to current version diff --git a/models/migrations/v85.go b/models/migrations/v85.go new file mode 100644 index 0000000000..1ca93d456d --- /dev/null +++ b/models/migrations/v85.go @@ -0,0 +1,25 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import ( + "github.com/go-xorm/xorm" +) + +func addTeamIsAllRepositories(x *xorm.Engine) error { + + type Team struct { + ID int64 `xorm:"pk autoincr"` + IsAllRepositories bool `xorm:"NOT NULL DEFAULT false"` + } + + if err := x.Sync2(new(Team)); err != nil { + return err + } + + _, err := x.Exec("UPDATE team SET is_all_repositories = ? WHERE name=?", + true, "Owners") + return err +} diff --git a/models/org.go b/models/org.go index b7db32ef16..4d7966b132 100644 --- a/models/org.go +++ b/models/org.go @@ -151,11 +151,12 @@ func CreateOrganization(org, owner *User) (err error) { // Create default owner team. t := &Team{ - OrgID: org.ID, - LowerName: strings.ToLower(ownerTeamName), - Name: ownerTeamName, - Authorize: AccessModeOwner, - NumMembers: 1, + OrgID: org.ID, + LowerName: strings.ToLower(ownerTeamName), + Name: ownerTeamName, + Authorize: AccessModeOwner, + NumMembers: 1, + IsAllRepositories: true, } if _, err = sess.Insert(t); err != nil { return fmt.Errorf("insert owner team: %v", err) diff --git a/models/org_team.go b/models/org_team.go index 49d06896e5..b6ef9fb34b 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -21,17 +21,18 @@ const ownerTeamName = "Owners" // Team represents a organization team. type Team struct { - ID int64 `xorm:"pk autoincr"` - OrgID int64 `xorm:"INDEX"` - LowerName string - Name string - Description string - Authorize AccessMode - Repos []*Repository `xorm:"-"` - Members []*User `xorm:"-"` - NumRepos int - NumMembers int - Units []*TeamUnit `xorm:"-"` + ID int64 `xorm:"pk autoincr"` + OrgID int64 `xorm:"INDEX"` + LowerName string + Name string + Description string + Authorize AccessMode + Repos []*Repository `xorm:"-"` + Members []*User `xorm:"-"` + NumRepos int + NumMembers int + Units []*TeamUnit `xorm:"-"` + IsAllRepositories bool `xorm:"NOT NULL DEFAULT false"` } // ColorFormat provides a basic color format for a Team