Skip to content

Commit 6a0e3de

Browse files
committed
remove orgnization watch repositories
1 parent a4cd461 commit 6a0e3de

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ var migrations = []Migration{
140140
NewMigration("remove duplicate unit types", removeDuplicateUnitTypes),
141141
// v45 -> v46
142142
NewMigration("remove index column from repo_unit table", removeIndexColumnFromRepoUnitTable),
143+
// v46 -> v47
144+
NewMigration("remove orgnization watch repositories", removeOrgnizationWatchRepo),
143145
}
144146

145147
// Migrate database to current version

models/migrations/v46.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"github.com/go-xorm/xorm"
9+
)
10+
11+
func removeOrgnizationWatchRepo(x *xorm.Engine) error {
12+
// Watch is connection request for receiving repository notification.
13+
type Watch struct {
14+
ID int64 `xorm:"pk autoincr"`
15+
UserID int64 `xorm:"UNIQUE(watch)"`
16+
RepoID int64 `xorm:"UNIQUE(watch)"`
17+
}
18+
19+
// UserType defines the user type
20+
type UserType int
21+
22+
const (
23+
// UserTypeIndividual defines an individual user
24+
UserTypeIndividual UserType = iota // Historic reason to make it starts at 0.
25+
26+
// UserTypeOrganization defines an organization
27+
UserTypeOrganization
28+
)
29+
30+
_, err := x.Join("INNER", "user", "watch.user_id = user.id").
31+
Where("user.`type` = ?", UserTypeOrganization).
32+
Delete(new(Watch))
33+
return err
34+
}

models/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
12951295
}
12961296
}
12971297

1298-
if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
1298+
if err = watchRepo(e, doer.ID, repo.ID, true); err != nil {
12991299
return fmt.Errorf("watchRepo: %v", err)
13001300
} else if err = newRepoAction(e, u, repo); err != nil {
13011301
return fmt.Errorf("newRepoAction: %v", err)

0 commit comments

Comments
 (0)