aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.bra.toml2
-rw-r--r--README.md6
-rw-r--r--README_ZH.md6
-rw-r--r--gogs.go2
-rw-r--r--models/access.go103
-rw-r--r--models/org.go85
-rw-r--r--models/repo.go131
-rw-r--r--modules/base/template.go2
-rw-r--r--modules/setting/setting.go14
-rw-r--r--routers/install.go1
-rw-r--r--routers/repo/setting.go8
-rw-r--r--routers/user/home.go22
-rw-r--r--templates/.VERSION2
13 files changed, 226 insertions, 158 deletions
diff --git a/.bra.toml b/.bra.toml
index 65b3988445..0f52fcdde5 100644
--- a/.bra.toml
+++ b/.bra.toml
@@ -1,6 +1,6 @@
[run]
init_cmds = [
- ["grep", "-rn", "FIXME", "."],
+ #["grep", "-rn", "FIXME", "."],
["./gogs", "web"]
]
watch_all = true
diff --git a/README.md b/README.md
index 150aa64de8..5bc45adaf7 100644
--- a/README.md
+++ b/README.md
@@ -7,13 +7,13 @@ Gogs (Go Git Service) is a painless self-hosted Git service written in Go.
![Demo](http://gogs.qiniudn.com/gogs_demo.gif)
-##### Current version: 0.5.13 Beta
+##### Current version: 0.5.16 Beta
### NOTICES
- Due to testing purpose, data of [try.gogs.io](https://try.gogs.io) has been reset in **Jan 28, 2015** and will reset multiple times after. Please do **NOT** put your important data on the site.
- The demo site [try.gogs.io](https://try.gogs.io) is running under `dev` branch.
-- You **MUST** read [CONTRIBUTING.md](CONTRIBUTING.md) before you start filing a issue or making a Pull Request.
+- You **MUST** read [CONTRIBUTING.md](CONTRIBUTING.md) before you start filing an issue or making a Pull Request.
- If you think there are vulnerabilities in the project, please talk privately to **u@gogs.io**. Thanks!
#### Other language version
@@ -57,7 +57,7 @@ The goal of this project is to make the easiest, fastest, and most painless way
## System Requirements
- A cheap Raspberry Pi is powerful enough for basic functionality.
-- At least 4 CPU cores and 1GB RAM would be the baseline for teamwork.
+- At least 2 CPU cores and 1GB RAM would be the baseline for teamwork.
## Installation
diff --git a/README_ZH.md b/README_ZH.md
index b6d74e7b14..1d2cfa3e84 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。
![Demo](http://gogs.qiniudn.com/gogs_demo.gif)
-##### 当前版本:0.5.13 Beta
+##### 当前版本:0.5.16 Beta
## 开发目的
@@ -44,7 +44,7 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自
## 系统要求
- 最低的系统硬件要求为一个廉价的树莓派
-- 如果用于团队项目,建议使用 4 核 CPU 及 1GB 内存
+- 如果用于团队项目,建议使用 2 核 CPU 及 1GB 内存
## 安装部署
@@ -75,4 +75,4 @@ Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自
## 授权许可
-本项目采用 MIT 开源授权许可证,完整的授权说明已放置在 [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) 文件中。 \ No newline at end of file
+本项目采用 MIT 开源授权许可证,完整的授权说明已放置在 [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) 文件中。
diff --git a/gogs.go b/gogs.go
index 58cbb1a05c..96c848ec3f 100644
--- a/gogs.go
+++ b/gogs.go
@@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
-const APP_VER = "0.5.15.0223 Beta"
+const APP_VER = "0.5.16.0228 Beta"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
diff --git a/models/access.go b/models/access.go
index 29d1a730b7..f353c39a2f 100644
--- a/models/access.go
+++ b/models/access.go
@@ -4,6 +4,10 @@
package models
+import (
+ "fmt"
+)
+
type AccessMode int
const (
@@ -83,6 +87,7 @@ func (u *User) GetAccessibleRepositories() (map[*Repository]AccessMode, error) {
repos[repo] = access.Mode
}
+ // FIXME: should we generate an ordered list here? Random looks weird.
return repos, nil
}
@@ -96,25 +101,58 @@ func maxAccessMode(modes ...AccessMode) AccessMode {
return max
}
-func (repo *Repository) recalculateTeamAccesses(e Engine, mode AccessMode) error {
+// FIXME: do corss-comparison so reduce deletions and additions to the minimum?
+func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]AccessMode) (err error) {
+ minMode := ACCESS_MODE_READ
+ if !repo.IsPrivate {
+ minMode = ACCESS_MODE_WRITE
+ }
+
+ newAccesses := make([]Access, 0, len(accessMap))
+ for userID, mode := range accessMap {
+ if mode < minMode {
+ continue
+ }
+ newAccesses = append(newAccesses, Access{
+ UserID: userID,
+ RepoID: repo.Id,
+ Mode: mode,
+ })
+ }
+ // Delete old accesses and insert new ones for repository.
+ if _, err = e.Delete(&Access{RepoID: repo.Id}); err != nil {
+ return fmt.Errorf("delete old accesses: %v", err)
+ } else if _, err = e.Insert(newAccesses); err != nil {
+ return fmt.Errorf("insert new accesses: %v", err)
+ }
return nil
}
-func (repo *Repository) recalculateAccesses(e Engine) error {
- accessMap := make(map[int64]AccessMode, 20)
-
- // FIXME: should be able to have read-only access.
- // Give all collaborators write access.
+// FIXME: should be able to have read-only access.
+// Give all collaborators write access.
+func (repo *Repository) refreshCollaboratorAccesses(e Engine, accessMap map[int64]AccessMode) error {
collaborators, err := repo.getCollaborators(e)
if err != nil {
- return err
+ return fmt.Errorf("getCollaborators: %v", err)
}
for _, c := range collaborators {
accessMap[c.Id] = ACCESS_MODE_WRITE
}
+ return nil
+}
+
+// recalculateTeamAccesses recalculates new accesses for teams of an organization
+// except the team whose ID is given. It is used to assign a team ID when
+// remove repository from that team.
+func (repo *Repository) recalculateTeamAccesses(e Engine, ignTeamID int64) (err error) {
+ accessMap := make(map[int64]AccessMode, 20)
+
+ if err = repo.refreshCollaboratorAccesses(e, accessMap); err != nil {
+ return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
+ }
- if err := repo.getOwner(e); err != nil {
+ if err = repo.getOwner(e); err != nil {
return err
}
if repo.Owner.IsOrganization() {
@@ -122,47 +160,32 @@ func (repo *Repository) recalculateAccesses(e Engine) error {
return err
}
- for _, team := range repo.Owner.Teams {
- if team.IsOwnerTeam() {
- team.Authorize = ACCESS_MODE_OWNER
+ for _, t := range repo.Owner.Teams {
+ if t.ID == ignTeamID {
+ continue
+ }
+ if t.IsOwnerTeam() {
+ t.Authorize = ACCESS_MODE_OWNER
}
- if err = team.getMembers(e); err != nil {
- return err
+ if err = t.getMembers(e); err != nil {
+ return fmt.Errorf("getMembers '%d': %v", t.ID, err)
}
- for _, u := range team.Members {
- accessMap[u.Id] = maxAccessMode(accessMap[u.Id], team.Authorize)
+ for _, m := range t.Members {
+ accessMap[m.Id] = maxAccessMode(accessMap[m.Id], t.Authorize)
}
}
}
- // FIXME: do corss-comparison so reduce deletions and additions to the minimum?
-
- minMode := ACCESS_MODE_READ
- if !repo.IsPrivate {
- minMode = ACCESS_MODE_WRITE
- }
-
- newAccesses := make([]Access, 0, len(accessMap))
- for userID, mode := range accessMap {
- if mode < minMode {
- continue
- }
- newAccesses = append(newAccesses, Access{
- UserID: userID,
- RepoID: repo.Id,
- Mode: mode,
- })
- }
+ return repo.refreshAccesses(e, accessMap)
+}
- // Delete old accesses and insert new ones for repository.
- if _, err = e.Delete(&Access{RepoID: repo.Id}); err != nil {
- return err
- } else if _, err = e.Insert(newAccesses); err != nil {
- return err
+func (repo *Repository) recalculateAccesses(e Engine) error {
+ accessMap := make(map[int64]AccessMode, 20)
+ if err := repo.refreshCollaboratorAccesses(e, accessMap); err != nil {
+ return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
}
-
- return nil
+ return repo.refreshAccesses(e, accessMap)
}
// RecalculateAccesses recalculates all accesses for repository.
diff --git a/models/org.go b/models/org.go
index 629e9345c3..2c2b9b6356 100644
--- a/models/org.go
+++ b/models/org.go
@@ -28,7 +28,7 @@ func (org *User) IsOwnedBy(uid int64) bool {
// IsOrgMember returns true if given user is member of organization.
func (org *User) IsOrgMember(uid int64) bool {
- return IsOrganizationMember(org.Id, uid)
+ return org.IsOrganization() && IsOrganizationMember(org.Id, uid)
}
func (org *User) getTeam(e Engine, name string) (*Team, error) {
@@ -85,6 +85,15 @@ func (org *User) RemoveMember(uid int64) error {
return RemoveOrgUser(org.Id, uid)
}
+func (org *User) removeOrgRepo(e Engine, repoID int64) error {
+ return removeOrgRepo(e, org.Id, repoID)
+}
+
+// RemoveOrgRepo removes all team-repository relations of organization.
+func (org *User) RemoveOrgRepo(repoID int64) error {
+ return org.removeOrgRepo(x, repoID)
+}
+
// IsOrgEmailUsed returns true if the e-mail has been used in organization account.
func IsOrgEmailUsed(email string) (bool, error) {
if len(email) == 0 {
@@ -364,7 +373,7 @@ func RemoveOrgUser(orgId, uid int64) error {
if _, err := sess.Id(ou.ID).Delete(ou); err != nil {
sess.Rollback()
return err
- } else if _, err = sess.Exec("UPDATE `user` SET num_members = num_members - 1 WHERE id = ?", orgId); err != nil {
+ } else if _, err = sess.Exec("UPDATE `user` SET num_members=num_members-1 WHERE id = ?", orgId); err != nil {
sess.Rollback()
return err
}
@@ -493,19 +502,19 @@ func (t *Team) addRepository(e Engine, repo *Repository) (err error) {
t.NumRepos++
if _, err = e.Id(t.ID).AllCols().Update(t); err != nil {
- return err
+ return fmt.Errorf("update team: %v", err)
}
- if err = repo.recalculateAccesses(e); err != nil {
- return err
+ if err = repo.recalculateTeamAccesses(e, 0); err != nil {
+ return fmt.Errorf("recalculateAccesses: %v", err)
}
if err = t.getMembers(e); err != nil {
- return fmt.Errorf("get team members: %v", err)
+ return fmt.Errorf("getMembers: %v", err)
}
for _, u := range t.Members {
if err = watchRepo(e, u.Id, repo.Id, true); err != nil {
- return err
+ return fmt.Errorf("watchRepo: %v", err)
}
}
return nil
@@ -532,7 +541,7 @@ func (t *Team) AddRepository(repo *Repository) (err error) {
return sess.Commit()
}
-func (t *Team) removeRepository(e Engine, repo *Repository) (err error) {
+func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (err error) {
if err = removeTeamRepo(e, t.ID, repo.Id); err != nil {
return err
}
@@ -542,8 +551,11 @@ func (t *Team) removeRepository(e Engine, repo *Repository) (err error) {
return err
}
- if err = repo.recalculateAccesses(e); err != nil {
- return err
+ // Don't need to recalculate when delete a repository from organization.
+ if recalculate {
+ if err = repo.recalculateTeamAccesses(e, t.ID); err != nil {
+ return err
+ }
}
if err = t.getMembers(e); err != nil {
@@ -582,7 +594,7 @@ func (t *Team) RemoveRepository(repoID int64) error {
return err
}
- if err = t.removeRepository(sess, repo); err != nil {
+ if err = t.removeRepository(sess, repo, true); err != nil {
return err
}
@@ -623,7 +635,7 @@ func NewTeam(t *Team) error {
}
// Update organization number of teams.
- if _, err = sess.Exec("UPDATE `user` SET num_teams = num_teams + 1 WHERE id = ?", t.OrgID); err != nil {
+ if _, err = sess.Exec("UPDATE `user` SET num_teams=num_teams+1 WHERE id = ?", t.OrgID); err != nil {
sess.Rollback()
return err
}
@@ -683,18 +695,18 @@ func UpdateTeam(t *Team, authChanged bool) (err error) {
t.LowerName = strings.ToLower(t.Name)
if _, err = sess.Id(t.ID).AllCols().Update(t); err != nil {
- return err
+ return fmt.Errorf("update: %v", err)
}
// Update access for team members if needed.
if authChanged {
if err = t.getRepositories(sess); err != nil {
- return err
+ return fmt.Errorf("getRepositories:%v", err)
}
for _, repo := range t.Repos {
- if err = repo.recalculateAccesses(sess); err != nil {
- return err
+ if err = repo.recalculateTeamAccesses(sess, 0); err != nil {
+ return fmt.Errorf("recalculateTeamAccesses: %v", err)
}
}
}
@@ -707,8 +719,6 @@ func UpdateTeam(t *Team, authChanged bool) (err error) {
func DeleteTeam(t *Team) error {
if err := t.GetRepositories(); err != nil {
return err
- } else if err = t.GetMembers(); err != nil {
- return err
}
// Get organization.
@@ -725,7 +735,7 @@ func DeleteTeam(t *Team) error {
// Delete all accesses.
for _, repo := range t.Repos {
- if err = repo.recalculateAccesses(sess); err != nil {
+ if err = repo.recalculateTeamAccesses(sess, t.ID); err != nil {
return err
}
}
@@ -772,10 +782,20 @@ func IsTeamMember(orgID, teamID, uid int64) bool {
return isTeamMember(x, orgID, teamID, uid)
}
-func getTeamMembers(e Engine, teamID int64) ([]*User, error) {
- us := make([]*User, 0, 10)
- err := e.Sql("SELECT * FROM `user` JOIN `team_user` ON `team_user`.`team_id` = ? AND `team_user`.`uid` = `user`.`id`", teamID).Find(&us)
- return us, err
+func getTeamMembers(e Engine, teamID int64) (_ []*User, err error) {
+ teamUsers := make([]*TeamUser, 0, 10)
+ if err = e.Where("team_id=?", teamID).Find(&teamUsers); err != nil {
+ return nil, fmt.Errorf("get team-users: %v", err)
+ }
+ members := make([]*User, 0, len(teamUsers))
+ for i := range teamUsers {
+ member := new(User)
+ if _, err = e.Id(teamUsers[i].Uid).Get(member); err != nil {
+ return nil, fmt.Errorf("get user '%d': %v", teamUsers[i].Uid, err)
+ }
+ members = append(members, member)
+ }
+ return members, nil
}
// GetTeamMembers returns all members in given team of organization.
@@ -840,7 +860,6 @@ func AddTeamMember(orgId, teamId, uid int64) error {
OrgID: orgId,
TeamID: teamId,
}
-
if _, err = sess.Insert(tu); err != nil {
return err
} else if _, err = sess.Id(t.ID).Update(t); err != nil {
@@ -849,7 +868,7 @@ func AddTeamMember(orgId, teamId, uid int64) error {
// Give access to team repositories.
for _, repo := range t.Repos {
- if err = repo.recalculateAccesses(sess); err != nil {
+ if err = repo.recalculateTeamAccesses(sess, 0); err != nil {
return err
}
}
@@ -903,7 +922,6 @@ func removeTeamMember(e Engine, orgId, teamId, uid int64) error {
OrgID: orgId,
TeamID: teamId,
}
-
if _, err := e.Delete(tu); err != nil {
return err
} else if _, err = e.Id(t.ID).AllCols().Update(t); err != nil {
@@ -912,7 +930,7 @@ func removeTeamMember(e Engine, orgId, teamId, uid int64) error {
// Delete access to team repositories.
for _, repo := range t.Repos {
- if err = repo.recalculateAccesses(e); err != nil {
+ if err = repo.recalculateTeamAccesses(e, 0); err != nil {
return err
}
}
@@ -997,3 +1015,16 @@ func removeTeamRepo(e Engine, teamID, repoID int64) error {
func RemoveTeamRepo(teamID, repoID int64) error {
return removeTeamRepo(x, teamID, repoID)
}
+
+func removeOrgRepo(e Engine, orgID, repoID int64) error {
+ _, err := e.Delete(&TeamRepo{
+ OrgID: orgID,
+ RepoID: repoID,
+ })
+ return err
+}
+
+// RemoveOrgRepo removes all team-repository relations of given organization.
+func RemoveOrgRepo(orgID, repoID int64) error {
+ return removeOrgRepo(x, orgID, repoID)
+}
diff --git a/models/repo.go b/models/repo.go
index 7f87bbb2a7..65cd368640 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -223,16 +223,12 @@ func (repo *Repository) DescriptionHtml() template.HTML {
}
// IsRepositoryExist returns true if the repository with given name under user has already existed.
-func IsRepositoryExist(u *User, repoName string) (bool, error) {
- repo := Repository{OwnerId: u.Id}
- has, err := x.Where("lower_name = ?", strings.ToLower(repoName)).Get(&repo)
- if err != nil {
- return has, err
- } else if !has {
- return false, nil
- }
-
- return com.IsDir(RepoPath(u.Name, repoName)), nil
+func IsRepositoryExist(u *User, repoName string) bool {
+ has, _ := x.Get(&Repository{
+ OwnerId: u.Id,
+ LowerName: strings.ToLower(repoName),
+ })
+ return has && com.IsDir(RepoPath(u.Name, repoName))
}
// CloneLink represents different types of clone URLs of repository.
@@ -514,15 +510,12 @@ func initRepository(e Engine, f string, u *User, repo *Repository, initReadme bo
}
// CreateRepository creates a repository for given user or organization.
-func CreateRepository(u *User, name, desc, lang, license string, isPrivate, isMirror, initReadme bool) (*Repository, error) {
+func CreateRepository(u *User, name, desc, lang, license string, isPrivate, isMirror, initReadme bool) (_ *Repository, err error) {
if !IsLegalName(name) {
return nil, ErrRepoNameIllegal
}
- isExist, err := IsRepositoryExist(u, name)
- if err != nil {
- return nil, err
- } else if isExist {
+ if IsRepositoryExist(u, name) {
return nil, ErrRepoAlreadyExist
}
@@ -551,11 +544,6 @@ func CreateRepository(u *User, name, desc, lang, license string, isPrivate, isMi
// Give access to all members in owner team.
if u.IsOrganization() {
- if err = repo.recalculateAccesses(sess); err != nil {
- return nil, err
- }
-
- // Update owner team info and count.
t, err := u.getOwnerTeam(sess)
if err != nil {
return nil, fmt.Errorf("getOwnerTeam: %v", err)
@@ -563,12 +551,15 @@ func CreateRepository(u *User, name, desc, lang, license string, isPrivate, isMi
return nil, fmt.Errorf("addRepository: %v", err)
}
} else {
- if err = watchRepo(sess, u.Id, repo.Id, true); err != nil {
- return nil, fmt.Errorf("watchRepo: %v", err)
+ // Organization called this in addRepository method.
+ if err = repo.recalculateAccesses(sess); err != nil {
+ return nil, fmt.Errorf("recalculateAccesses: %v", err)
}
}
- if err = newRepoAction(sess, u, repo); err != nil {
+ if err = watchRepo(sess, u.Id, repo.Id, true); err != nil {
+ return nil, fmt.Errorf("watchRepo: %v", err)
+ } else if err = newRepoAction(sess, u, repo); err != nil {
return nil, fmt.Errorf("newRepoAction: %v", err)
}
@@ -631,71 +622,100 @@ func RepoPath(userName, repoName string) string {
func TransferOwnership(u *User, newOwnerName string, repo *Repository) error {
newOwner, err := GetUserByName(newOwnerName)
if err != nil {
- return fmt.Errorf("get new owner(%s): %v", newOwnerName, err)
+ return fmt.Errorf("get new owner '%s': %v", newOwnerName, err)
}
// Check if new owner has repository with same name.
- has, err := IsRepositoryExist(newOwner, repo.Name)
- if err != nil {
- return err
- } else if has {
+ if IsRepositoryExist(newOwner, repo.Name) {
return ErrRepoAlreadyExist
}
sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
- return err
+ return fmt.Errorf("sess.Begin: %v", err)
}
owner := repo.Owner
- // Update repository.
+ // Note: we have to set value here to make sure recalculate accesses is based on
+ // new owner.
repo.OwnerId = newOwner.Id
repo.Owner = newOwner
+
+ // Update repository.
if _, err := sess.Id(repo.Id).Update(repo); err != nil {
- return err
+ return fmt.Errorf("update owner: %v", err)
}
- // Remove redundant collaborators
+ // Remove redundant collaborators.
collaborators, err := repo.GetCollaborators()
if err != nil {
- return err
+ return fmt.Errorf("GetCollaborators: %v", err)
}
+
+ // Dummy object.
+ collaboration := &Collaboration{RepoID: repo.Id}
for _, c := range collaborators {
+ collaboration.UserID = c.Id
if c.Id == newOwner.Id || newOwner.IsOrgMember(c.Id) {
- if _, err = sess.Delete(&Collaboration{RepoID: repo.Id, UserID: c.Id}); err != nil {
- return err
+ if _, err = sess.Delete(collaboration); err != nil {
+ return fmt.Errorf("remove collaborator '%d': %v", c.Id, err)
}
}
}
+ // Remove old team-repository relations.
+ if owner.IsOrganization() {
+ if err = owner.getTeams(sess); err != nil {
+ return fmt.Errorf("getTeams: %v", err)
+ }
+ for _, t := range owner.Teams {
+ if !t.hasRepository(sess, repo.Id) {
+ continue
+ }
+
+ t.NumRepos--
+ if _, err := sess.Id(t.ID).AllCols().Update(t); err != nil {
+ return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err)
+ }
+ }
+
+ if err = owner.removeOrgRepo(sess, repo.Id); err != nil {
+ return fmt.Errorf("removeOrgRepo: %v", err)
+ }
+ }
+
if newOwner.IsOrganization() {
- // Update owner team info and count.
t, err := newOwner.GetOwnerTeam()
if err != nil {
- return err
+ return fmt.Errorf("GetOwnerTeam: %v", err)
} else if err = t.addRepository(sess, repo); err != nil {
- return err
+ return fmt.Errorf("add to owner team: %v", err)
+ }
+ } else {
+ // Organization called this in addRepository method.
+ if err = repo.recalculateAccesses(sess); err != nil {
+ return fmt.Errorf("recalculateAccesses: %v", err)
}
}
- // Update user repository number.
- if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos + 1 WHERE id = ?", newOwner.Id); err != nil {
- return err
- } else if _, err = sess.Exec("UPDATE `user` SET num_repos = num_repos - 1 WHERE id = ?", owner.Id); err != nil {
- return err
- } else if err = repo.recalculateAccesses(sess); err != nil {
- return err
- } else if err = watchRepo(sess, newOwner.Id, repo.Id, true); err != nil {
- return err
+ // Update repository count.
+ if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.Id); err != nil {
+ return fmt.Errorf("increase new owner repository count: %v", err)
+ } else if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", owner.Id); err != nil {
+ return fmt.Errorf("decrease old owner repository count: %v", err)
+ }
+
+ if err = watchRepo(sess, newOwner.Id, repo.Id, true); err != nil {
+ return fmt.Errorf("watchRepo: %v", err)
} else if err = transferRepoAction(sess, u, owner, newOwner, repo); err != nil {
- return err
+ return fmt.Errorf("transferRepoAction: %v", err)
}
// Change repository directory name.
if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
- return err
+ return fmt.Errorf("rename directory: %v", err)
}
return sess.Commit()
@@ -762,7 +782,7 @@ func DeleteRepository(uid, repoID int64, userName string) error {
for _, t := range org.Teams {
if !t.hasRepository(sess, repoID) {
continue
- } else if err = t.removeRepository(sess, repo); err != nil {
+ } else if err = t.removeRepository(sess, repo, false); err != nil {
return err
}
}
@@ -770,9 +790,9 @@ func DeleteRepository(uid, repoID int64, userName string) error {
if _, err = sess.Delete(&Repository{Id: repoID}); err != nil {
return err
- } else if _, err := sess.Delete(&Access{RepoID: repo.Id}); err != nil {
+ } else if _, err = sess.Delete(&Access{RepoID: repo.Id}); err != nil {
return err
- } else if _, err := sess.Delete(&Action{RepoId: repo.Id}); err != nil {
+ } else if _, err = sess.Delete(&Action{RepoId: repo.Id}); err != nil {
return err
} else if _, err = sess.Delete(&Watch{RepoId: repoID}); err != nil {
return err
@@ -1275,11 +1295,8 @@ func IsStaring(uid, repoId int64) bool {
// \___ / \____/|__| |__|_ \
// \/ \/
-func ForkRepository(u *User, oldRepo *Repository, name, desc string) (*Repository, error) {
- isExist, err := IsRepositoryExist(u, name)
- if err != nil {
- return nil, err
- } else if isExist {
+func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
+ if IsRepositoryExist(u, name) {
return nil, ErrRepoAlreadyExist
}
diff --git a/modules/base/template.go b/modules/base/template.go
index cfcabb71a2..196b935107 100644
--- a/modules/base/template.go
+++ b/modules/base/template.go
@@ -164,7 +164,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
},
"DiffTypeToStr": DiffTypeToStr,
"DiffLineTypeToStr": DiffLineTypeToStr,
- "Sha1": Sha1,
+ "Sha1": Sha1,
"ShortSha": ShortSha,
"Md5": EncodeMd5,
"ActionContent2Commits": ActionContent2Commits,
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 6a36105691..6db43b16b3 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -272,10 +272,6 @@ func NewConfigContext() {
"StampNano": time.StampNano,
}[Cfg.Section("time").Key("FORMAT").MustString("RFC1123")]
- if err = os.MkdirAll(AttachmentPath, os.ModePerm); err != nil {
- log.Fatal(4, "Could not create directory %s: %s", AttachmentPath, err)
- }
-
RunUser = Cfg.Section("").Key("RUN_USER").String()
curUser := os.Getenv("USER")
if len(curUser) == 0 {
@@ -298,9 +294,6 @@ func NewConfigContext() {
} else {
RepoRootPath = filepath.Clean(RepoRootPath)
}
- if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
- log.Fatal(4, "Fail to create repository root path(%s): %v", RepoRootPath, err)
- }
ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")
sec = Cfg.Section("picture")
@@ -309,7 +302,6 @@ func NewConfigContext() {
if !filepath.IsAbs(AvatarUploadPath) {
AvatarUploadPath = path.Join(workDir, AvatarUploadPath)
}
- os.MkdirAll(AvatarUploadPath, os.ModePerm)
switch sec.Key("GRAVATAR_SOURCE").MustString("gravatar") {
case "duoshuo":
GravatarSource = "http://gravatar.duoshuo.com/avatar/"
@@ -374,9 +366,11 @@ func newLogService() {
log.Fatal(4, "Unknown log mode: %s", mode)
}
+ validLevels := []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}
// Log level.
- levelName := Cfg.Section("log."+mode).Key("LEVEL").In("Trace",
- []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"})
+ levelName := Cfg.Section("log."+mode).Key("LEVEL").In(
+ Cfg.Section("log").Key("LEVEL").In("Trace", validLevels),
+ validLevels)
level, ok := logLevels[levelName]
if !ok {
log.Fatal(4, "Unknown log level: %s", levelName)
diff --git a/routers/install.go b/routers/install.go
index a7828e351c..4aa3ca9306 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -224,6 +224,7 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
cfg.Section("session").Key("PROVIDER").SetValue("file")
cfg.Section("log").Key("MODE").SetValue("file")
+ cfg.Section("log").Key("LEVEL").SetValue("Info")
cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
cfg.Section("security").Key("SECRET_KEY").SetValue(base.GetRandomString(15))
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index e2b8968375..5cd39ada2c 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -53,15 +53,11 @@ func SettingsPost(ctx *middleware.Context, form auth.RepoSettingForm) {
newRepoName := form.RepoName
// Check if repository name has been changed.
if ctx.Repo.Repository.Name != newRepoName {
- isExist, err := models.IsRepositoryExist(ctx.Repo.Owner, newRepoName)
- if err != nil {
- ctx.Handle(500, "IsRepositoryExist", err)
- return
- } else if isExist {
+ if models.IsRepositoryExist(ctx.Repo.Owner, newRepoName) {
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), SETTINGS_OPTIONS, nil)
return
- } else if err = models.ChangeRepositoryName(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newRepoName); err != nil {
+ } else if err := models.ChangeRepositoryName(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newRepoName); err != nil {
if err == models.ErrRepoNameIllegal {
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("form.illegal_repo_name"), SETTINGS_OPTIONS, nil)
diff --git a/routers/user/home.go b/routers/user/home.go
index 35407534f9..0a1d9dd217 100644
--- a/routers/user/home.go
+++ b/routers/user/home.go
@@ -103,9 +103,14 @@ func Dashboard(ctx *middleware.Context) {
feeds := make([]*models.Action, 0, len(actions))
for _, act := range actions {
if act.IsPrivate {
- if has, _ := models.HasAccess(ctx.User, &models.Repository{Id: act.RepoId, IsPrivate: true}, models.ACCESS_MODE_READ); !has {
- continue
+ // This prevents having to retrieve the repository for each action
+ repo := &models.Repository{Id: act.RepoId, IsPrivate: true}
+ if act.RepoUserName != ctx.User.LowerName {
+ if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has {
+ continue
+ }
}
+
}
// FIXME: cache results?
u, err := models.GetUserByName(act.ActUserName)
@@ -210,13 +215,14 @@ func Profile(ctx *middleware.Context) {
if !ctx.IsSigned {
continue
}
- if has, _ := models.HasAccess(ctx.User,
- &models.Repository{
- Id: act.RepoId,
- IsPrivate: true,
- }, models.ACCESS_MODE_READ); !has {
- continue
+ // This prevents having to retrieve the repository for each action
+ repo := &models.Repository{Id: act.RepoId, IsPrivate: true}
+ if act.RepoUserName != ctx.User.LowerName {
+ if has, _ := models.HasAccess(ctx.User, repo, models.ACCESS_MODE_READ); !has {
+ continue
+ }
}
+
}
// FIXME: cache results?
u, err := models.GetUserByName(act.ActUserName)
diff --git a/templates/.VERSION b/templates/.VERSION
index 4758bb670f..0789cc30bc 100644
--- a/templates/.VERSION
+++ b/templates/.VERSION
@@ -1 +1 @@
-0.5.15.0223 Beta \ No newline at end of file
+0.5.16.0228 Beta \ No newline at end of file