summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-08-10 20:11:18 -0700
committerUnknwon <joe2010xtmf@163.com>2014-08-10 20:11:18 -0700
commit5fbf8531e6a2b74ebc9dd2a5967e82a8c9216c7a (patch)
tree8c657d037a5c87ec13cc828244ae30d3fe1168ab /models
parent7af7584d25f48309a70083c30805ebb8454611f0 (diff)
downloadgitea-5fbf8531e6a2b74ebc9dd2a5967e82a8c9216c7a.tar.gz
gitea-5fbf8531e6a2b74ebc9dd2a5967e82a8c9216c7a.zip
Finish new home page of organization
Diffstat (limited to 'models')
-rw-r--r--models/models.go5
-rw-r--r--models/org.go1
-rw-r--r--models/repo.go62
3 files changed, 58 insertions, 10 deletions
diff --git a/models/models.go b/models/models.go
index af9529f40a..bf2586063b 100644
--- a/models/models.go
+++ b/models/models.go
@@ -32,8 +32,9 @@ var (
)
func init() {
- tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
- new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow),
+ tables = append(tables, new(User), new(PublicKey),
+ new(Repository), new(Watch), new(Star), new(Action), new(Access),
+ new(Issue), new(Comment), new(Oauth2), new(Follow),
new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser),
new(Milestone), new(Label), new(HookTask), new(Team), new(OrgUser), new(TeamUser),
new(UpdateTask), new(Attachment))
diff --git a/models/org.go b/models/org.go
index 2efef534b4..edae828b54 100644
--- a/models/org.go
+++ b/models/org.go
@@ -106,6 +106,7 @@ func CreateOrganization(org, owner *User) (*User, error) {
// Create default owner team.
t := &Team{
OrgId: org.Id,
+ LowerName: strings.ToLower(OWNER_TEAM),
Name: OWNER_TEAM,
Authorize: ORG_ADMIN,
NumMembers: 1,
diff --git a/models/repo.go b/models/repo.go
index c2398fe7da..bec3cb212f 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -137,6 +137,7 @@ type Repository struct {
NumTags int `xorm:"-"`
IsPrivate bool
IsMirror bool
+ *Mirror `xorm:"-"`
IsFork bool `xorm:"NOT NULL DEFAULT false"`
IsBare bool
IsGoget bool
@@ -150,6 +151,11 @@ func (repo *Repository) GetOwner() (err error) {
return err
}
+func (repo *Repository) GetMirror() (err error) {
+ repo.Mirror, err = GetMirror(repo.Id)
+ return err
+}
+
// DescriptionHtml does special handles to description and return HTML string.
func (repo *Repository) DescriptionHtml() template.HTML {
sanitize := func(s string) string {
@@ -953,21 +959,33 @@ type Watch struct {
}
// Watch or unwatch repository.
-func WatchRepo(uid, rid int64, watch bool) (err error) {
+func WatchRepo(uid, repoId int64, watch bool) (err error) {
if watch {
- if _, err = x.Insert(&Watch{RepoId: rid, UserId: uid}); err != nil {
+ if IsWatching(uid, repoId) {
+ return nil
+ }
+ if _, err = x.Insert(&Watch{RepoId: repoId, UserId: uid}); err != nil {
return err
}
- _, err = x.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", rid)
+ _, err = x.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", repoId)
} else {
- if _, err = x.Delete(&Watch{0, uid, rid}); err != nil {
+ if !IsWatching(uid, repoId) {
+ return nil
+ }
+ if _, err = x.Delete(&Watch{0, uid, repoId}); err != nil {
return err
}
- _, err = x.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", rid)
+ _, err = x.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", repoId)
}
return err
}
+// IsWatching checks if user has watched given repository.
+func IsWatching(uid, rid int64) bool {
+ has, _ := x.Get(&Watch{0, uid, rid})
+ return has
+}
+
// GetWatchers returns all watchers of given repository.
func GetWatchers(rid int64) ([]*Watch, error) {
watches := make([]*Watch, 0, 10)
@@ -1003,9 +1021,37 @@ func NotifyWatchers(act *Action) error {
return nil
}
-// IsWatching checks if user has watched given repository.
-func IsWatching(uid, rid int64) bool {
- has, _ := x.Get(&Watch{0, uid, rid})
+type Star struct {
+ Id int64
+ Uid int64 `xorm:"UNIQUE(s)"`
+ RepoId int64 `xorm:"UNIQUE(s)"`
+}
+
+// Star or unstar repository.
+func StarRepo(uid, repoId int64, star bool) (err error) {
+ if star {
+ if IsStaring(uid, repoId) {
+ return nil
+ }
+ if _, err = x.Insert(&Star{Uid: uid, RepoId: repoId}); err != nil {
+ return err
+ }
+ _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars + 1 WHERE id = ?", repoId)
+ } else {
+ if !IsStaring(uid, repoId) {
+ return nil
+ }
+ if _, err = x.Delete(&Star{0, uid, repoId}); err != nil {
+ return err
+ }
+ _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars - 1 WHERE id = ?", repoId)
+ }
+ return err
+}
+
+// IsStaring checks if user has starred given repository.
+func IsStaring(uid, repoId int64) bool {
+ has, _ := x.Get(&Star{0, uid, repoId})
return has
}