Browse Source

repo: assignee can be anyone who has read access (#3739)

pull/4150/head
Unknwon 8 years ago
parent
commit
266586e866
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      gogs.go
  2. 8
      models/access.go
  3. 2
      models/issue.go
  4. 3
      models/repo.go
  5. 22
      models/repo_collaboration.go
  6. 2
      models/user.go
  7. 2
      public/js/gogs.js
  8. 5
      routers/repo/setting.go
  9. 2
      templates/.VERSION

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.155.0217" const APP_VER = "0.9.156.0217"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

8
models/access.go

@ -146,16 +146,8 @@ func maxAccessMode(modes ...AccessMode) AccessMode {
// FIXME: do corss-comparison so reduce deletions and additions to the minimum? // FIXME: do corss-comparison so reduce deletions and additions to the minimum?
func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]AccessMode) (err error) { 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)) newAccesses := make([]Access, 0, len(accessMap))
for userID, mode := range accessMap { for userID, mode := range accessMap {
if mode < minMode {
continue
}
newAccesses = append(newAccesses, Access{ newAccesses = append(newAccesses, Access{
UserID: userID, UserID: userID,
RepoID: repo.ID, RepoID: repo.ID,

2
models/issue.go

@ -618,7 +618,7 @@ func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) {
// Assume assignee is invalid and drop silently. // Assume assignee is invalid and drop silently.
opts.Issue.AssigneeID = 0 opts.Issue.AssigneeID = 0
if assignee != nil { if assignee != nil {
valid, err := hasAccess(e, assignee, opts.Repo, ACCESS_MODE_WRITE) valid, err := hasAccess(e, assignee, opts.Repo, ACCESS_MODE_READ)
if err != nil { if err != nil {
return fmt.Errorf("hasAccess [user_id: %d, repo_id: %d]: %v", assignee.ID, opts.Repo.ID, err) return fmt.Errorf("hasAccess [user_id: %d, repo_id: %d]: %v", assignee.ID, opts.Repo.ID, err)
} }

3
models/repo.go

@ -328,13 +328,14 @@ func (repo *Repository) DeleteWiki() {
} }
} }
// getAssignees returns a list of users who can be assigned to issues in this repository.
func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) { func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
if err = repo.getOwner(e); err != nil { if err = repo.getOwner(e); err != nil {
return nil, err return nil, err
} }
accesses := make([]*Access, 0, 10) accesses := make([]*Access, 0, 10)
if err = e.Where("repo_id = ? AND mode >= ?", repo.ID, ACCESS_MODE_WRITE).Find(&accesses); err != nil { if err = e.Where("repo_id = ? AND mode >= ?", repo.ID, ACCESS_MODE_READ).Find(&accesses); err != nil {
return nil, err return nil, err
} }

22
models/repo_collaboration.go

@ -126,7 +126,7 @@ func (repo *Repository) GetCollaborators() ([]*Collaborator, error) {
} }
// ChangeCollaborationAccessMode sets new access mode for the collaboration. // ChangeCollaborationAccessMode sets new access mode for the collaboration.
func (repo *Repository) ChangeCollaborationAccessMode(uid int64, mode AccessMode) error { func (repo *Repository) ChangeCollaborationAccessMode(userID int64, mode AccessMode) error {
// Discard invalid input // Discard invalid input
if mode <= ACCESS_MODE_NONE || mode > ACCESS_MODE_OWNER { if mode <= ACCESS_MODE_NONE || mode > ACCESS_MODE_OWNER {
return nil return nil
@ -134,7 +134,7 @@ func (repo *Repository) ChangeCollaborationAccessMode(uid int64, mode AccessMode
collaboration := &Collaboration{ collaboration := &Collaboration{
RepoID: repo.ID, RepoID: repo.ID,
UserID: uid, UserID: userID,
} }
has, err := x.Get(collaboration) has, err := x.Get(collaboration)
if err != nil { if err != nil {
@ -156,7 +156,23 @@ func (repo *Repository) ChangeCollaborationAccessMode(uid int64, mode AccessMode
if _, err = sess.Id(collaboration.ID).AllCols().Update(collaboration); err != nil { if _, err = sess.Id(collaboration.ID).AllCols().Update(collaboration); err != nil {
return fmt.Errorf("update collaboration: %v", err) return fmt.Errorf("update collaboration: %v", err)
} else if _, err = sess.Exec("UPDATE access SET mode = ? WHERE user_id = ? AND repo_id = ?", mode, uid, repo.ID); err != nil { }
access := Access{
UserID: userID,
RepoID: repo.ID,
}
has, err = sess.Get(access)
if err != nil {
return fmt.Errorf("get access record: %v", err)
}
if has {
_, err = sess.Exec("UPDATE access SET mode = ? WHERE user_id = ? AND repo_id = ?", mode, userID, repo.ID)
} else {
access.Mode = mode
_, err = sess.Insert(access)
}
if err != nil {
return fmt.Errorf("update access table: %v", err) return fmt.Errorf("update access table: %v", err)
} }

2
models/user.go

@ -911,7 +911,7 @@ func GetUserByID(id int64) (*User, error) {
// GetAssigneeByID returns the user with write access of repository by given ID. // GetAssigneeByID returns the user with write access of repository by given ID.
func GetAssigneeByID(repo *Repository, userID int64) (*User, error) { func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
has, err := HasAccess(&User{ID: userID}, repo, ACCESS_MODE_WRITE) has, err := HasAccess(&User{ID: userID}, repo, ACCESS_MODE_READ)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {

2
public/js/gogs.js

@ -1153,7 +1153,7 @@ function searchRepositories() {
if (response.ok && response.data.length) { if (response.ok && response.data.length) {
var html = ''; var html = '';
$.each(response.data, function (i, item) { $.each(response.data, function (i, item) {
html += '<div class="item"><i class="icon octicon octicon-repo"></i> <span class="fullname">' + item.full_name + '</span></div>'; html += '<div class="item"><i class="octicon octicon-repo"></i> <span class="fullname">' + item.full_name + '</span></div>';
}); });
$results.html(html); $results.html(html);
$this.find('.results .item').click(function () { $this.find('.results .item').click(function () {

5
routers/repo/setting.go

@ -351,8 +351,11 @@ func ChangeCollaborationAccessMode(ctx *context.Context) {
if err := ctx.Repo.Repository.ChangeCollaborationAccessMode( if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(
ctx.QueryInt64("uid"), ctx.QueryInt64("uid"),
models.AccessMode(ctx.QueryInt("mode"))); err != nil { models.AccessMode(ctx.QueryInt("mode"))); err != nil {
log.Error(4, "ChangeCollaborationAccessMode: %v", err) log.Error(2, "ChangeCollaborationAccessMode: %v", err)
return
} }
ctx.Status(204)
} }
func DeleteCollaboration(ctx *context.Context) { func DeleteCollaboration(ctx *context.Context) {

2
templates/.VERSION

@ -1 +1 @@
0.9.155.0217 0.9.156.0217
Loading…
Cancel
Save