Browse Source

repo: able to add organization member as repository collaborator

pull/3853/merge
Unknwon 8 years ago
parent
commit
10b93efc4a
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 1
      conf/locale/locale_en-US.ini
  2. 2
      gogs.go
  3. 2
      models/access.go
  4. 37
      models/org_team.go
  5. 28
      models/repo_collaboration.go
  6. 6
      modules/bindata/bindata.go
  7. 9
      routers/repo/setting.go
  8. 2
      templates/.VERSION

1
conf/locale/locale_en-US.ini

@ -722,7 +722,6 @@ settings.collaborator_deletion_desc = This user will no longer have collaboratio
settings.remove_collaborator_success = Collaborator has been removed.
settings.search_user_placeholder = Search user...
settings.org_not_allowed_to_be_collaborator = Organization is not allowed to be added as a collaborator.
settings.user_is_org_member = User is organization member who cannot be added as a collaborator.
settings.add_webhook = Add Webhook
settings.hooks_desc = Webhooks are much like basic HTTP POST event triggers. Whenever something occurs in Gogs, we will handle the notification to the target host you specify. Learn more in this <a target="_blank" href="%s">Webhooks Guide</a>.
settings.webhook_deletion = Delete Webhook

2
gogs.go

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

2
models/access.go

@ -229,7 +229,7 @@ func (repo *Repository) recalculateAccesses(e Engine) error {
return repo.recalculateTeamAccesses(e, 0)
}
accessMap := make(map[int64]AccessMode, 20)
accessMap := make(map[int64]AccessMode, 10)
if err := repo.refreshCollaboratorAccesses(e, accessMap); err != nil {
return fmt.Errorf("refreshCollaboratorAccesses: %v", err)
}

37
models/org_team.go

@ -444,39 +444,34 @@ func GetTeamMembers(teamID int64) ([]*User, error) {
return getTeamMembers(x, teamID)
}
func getUserTeams(e Engine, orgId, uid int64) ([]*Team, error) {
tus := make([]*TeamUser, 0, 5)
if err := e.Where("uid=?", uid).And("org_id=?", orgId).Find(&tus); err != nil {
func getUserTeams(e Engine, orgID, userID int64) ([]*Team, error) {
teamUsers := make([]*TeamUser, 0, 5)
if err := e.Where("uid = ?", userID).And("org_id = ?", orgID).Find(&teamUsers); err != nil {
return nil, err
}
ts := make([]*Team, len(tus))
for i, tu := range tus {
t := new(Team)
has, err := e.Id(tu.TeamID).Get(t)
if err != nil {
return nil, err
} else if !has {
return nil, ErrTeamNotExist
}
ts[i] = t
teamIDs := make([]int64, len(teamUsers))
for i := range teamUsers {
teamIDs[i] = teamUsers[i].TeamID
}
return ts, nil
teams := make([]*Team, 0, len(teamIDs))
return teams, e.Where("org_id = ?", orgID).In("id", teamIDs).Find(&teams)
}
// GetUserTeams returns all teams that user belongs to in given organization.
func GetUserTeams(orgId, uid int64) ([]*Team, error) {
return getUserTeams(x, orgId, uid)
func GetUserTeams(orgID, userID int64) ([]*Team, error) {
return getUserTeams(x, orgID, userID)
}
// AddTeamMember adds new membership of given team to given organization,
// the user will have membership to given organization automatically when needed.
func AddTeamMember(orgID, teamID, uid int64) error {
if IsTeamMember(orgID, teamID, uid) {
func AddTeamMember(orgID, teamID, userID int64) error {
if IsTeamMember(orgID, teamID, userID) {
return nil
}
if err := AddOrgUser(orgID, uid); err != nil {
if err := AddOrgUser(orgID, userID); err != nil {
return err
}
@ -498,7 +493,7 @@ func AddTeamMember(orgID, teamID, uid int64) error {
}
tu := &TeamUser{
UID: uid,
UID: userID,
OrgID: orgID,
TeamID: teamID,
}
@ -517,7 +512,7 @@ func AddTeamMember(orgID, teamID, uid int64) error {
// We make sure it exists before.
ou := new(OrgUser)
if _, err = sess.Where("uid = ?", uid).And("org_id = ?", orgID).Get(ou); err != nil {
if _, err = sess.Where("uid = ?", userID).And("org_id = ?", orgID).Get(ou); err != nil {
return err
}
ou.NumTeams++

28
models/repo_collaboration.go

@ -62,17 +62,10 @@ func (repo *Repository) AddCollaborator(u *User) error {
return err
}
if _, err = sess.InsertOne(collaboration); err != nil {
if _, err = sess.Insert(collaboration); err != nil {
return err
}
if repo.Owner.IsOrganization() {
err = repo.recalculateTeamAccesses(sess, 0)
} else {
err = repo.recalculateAccesses(sess)
}
if err != nil {
return fmt.Errorf("recalculateAccesses 'team=%v': %v", repo.Owner.IsOrganization(), err)
} else if err = repo.recalculateAccesses(sess); err != nil {
return fmt.Errorf("recalculateAccesses [repo_id: %v]: %v", repo.ID, err)
}
return sess.Commit()
@ -148,6 +141,19 @@ func (repo *Repository) ChangeCollaborationAccessMode(userID int64, mode AccessM
}
collaboration.Mode = mode
// If it's an organizational repository, merge with team access level for highest permission
if repo.Owner.IsOrganization() {
teams, err := GetUserTeams(repo.OwnerID, userID)
if err != nil {
return fmt.Errorf("GetUserTeams: [org_id: %d, user_id: %d]: %v", repo.OwnerID, userID, err)
}
for i := range teams {
if mode < teams[i].Authorize {
mode = teams[i].Authorize
}
}
}
sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
@ -173,7 +179,7 @@ func (repo *Repository) ChangeCollaborationAccessMode(userID int64, mode AccessM
_, err = sess.Insert(access)
}
if err != nil {
return fmt.Errorf("update access table: %v", err)
return fmt.Errorf("update/insert access table: %v", err)
}
return sess.Commit()

6
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

9
routers/repo/setting.go

@ -320,20 +320,13 @@ func SettingsCollaborationPost(ctx *context.Context) {
return
}
// Organization is not allowed to be added as a collaborator.
// Organization is not allowed to be added as a collaborator
if u.IsOrganization() {
ctx.Flash.Error(ctx.Tr("repo.settings.org_not_allowed_to_be_collaborator"))
ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
return
}
// Check if user is organization member.
if ctx.Repo.Owner.IsOrganization() && ctx.Repo.Owner.IsOrgMember(u.ID) {
ctx.Flash.Info(ctx.Tr("repo.settings.user_is_org_member"))
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
return
}
if err = ctx.Repo.Repository.AddCollaborator(u); err != nil {
ctx.Handle(500, "AddCollaborator", err)
return

2
templates/.VERSION

@ -1 +1 @@
0.9.168.0223 / 0.10 RC
0.9.169.0224 / 0.10 RC
Loading…
Cancel
Save