Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] orgEditTeam make Fields optional #9556

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b49e4a8
API: orgEditTeam make Fields optional
6543 Dec 31, 2019
ecc15a5
add TestCase
6543 Jan 2, 2020
0c76d5c
Update integrations/api_team_test.go
6543 Jan 2, 2020
c5ed8bf
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 2, 2020
a9a0f9b
suggestions from lafriks
6543 Jan 2, 2020
89ef6aa
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 2, 2020
322d657
change ...
6543 Jan 4, 2020
bae6724
use Where not ID to get mssql
6543 Jan 4, 2020
ad12e31
add return and code format
6543 Jan 4, 2020
ccb0f9f
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 4, 2020
f52f736
fix test
6543 Jan 4, 2020
02a87c9
fix test ... null pointer exept
6543 Jan 4, 2020
c263119
update specific colums
6543 Jan 4, 2020
6d36861
only specific colums too
6543 Jan 4, 2020
2dadeea
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 4, 2020
3b41462
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 6, 2020
60096e4
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 6, 2020
23fef55
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 7, 2020
6078b3c
Merge branch 'master' into api-orgEditTeam_make-Name-optional
lunny Jan 8, 2020
67d60ab
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 8, 2020
1bd9e32
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 9, 2020
cb9b3a9
Merge branch 'master' into api-orgEditTeam_make-Name-optional
6543 Jan 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
API: orgEditTeam make Fields optional
  • Loading branch information
6543 committed Jan 2, 2020
commit b49e4a848b36480106a13ec7da397c641b67cb3f
4 changes: 2 additions & 2 deletions modules/structs/org_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ type CreateTeamOption struct {
// EditTeamOption options for editing a team
type EditTeamOption struct {
// required: true
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
Name string `json:"name" binding:"AlphaDashDot;MaxSize(30)"`
Description string `json:"description" binding:"MaxSize(255)"`
IncludesAllRepositories bool `json:"includes_all_repositories"`
// enum: read,write,admin
Permission string `json:"permission"`
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.ext_wiki"]
Units []string `json:"units"`
CanCreateOrgRepo bool `json:"can_create_org_repo"`
CanCreateOrgRepo *bool `json:"can_create_org_repo"`
}
38 changes: 26 additions & 12 deletions routers/api/v1/org/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,28 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) {
// "$ref": "#/responses/Team"

team := ctx.Org.Team
team.Description = form.Description
unitTypes := models.FindUnitTypes(form.Units...)
team.CanCreateOrgRepo = form.CanCreateOrgRepo
if err := team.GetUnits(); err != nil {
ctx.InternalServerError(err)
6543 marked this conversation as resolved.
Show resolved Hide resolved
}

if form.CanCreateOrgRepo != nil {
team.CanCreateOrgRepo = *form.CanCreateOrgRepo
}

if form.Name != "" {
6543 marked this conversation as resolved.
Show resolved Hide resolved
team.Name = form.Name
}

if form.Description != "" {
6543 marked this conversation as resolved.
Show resolved Hide resolved
team.Description = form.Description
}

isAuthChanged := false
isIncludeAllChanged := false
if !team.IsOwnerTeam() {
if !team.IsOwnerTeam() && form.Permission != "" {
6543 marked this conversation as resolved.
Show resolved Hide resolved
// Validate permission level.
auth := models.ParseAccessMode(form.Permission)

team.Name = form.Name
if team.Authorize != auth {
isAuthChanged = true
team.Authorize = auth
Expand All @@ -215,14 +226,17 @@ func EditTeam(ctx *context.APIContext, form api.EditTeamOption) {
}

if team.Authorize < models.AccessModeOwner {
var units = make([]*models.TeamUnit, 0, len(form.Units))
for _, tp := range unitTypes {
units = append(units, &models.TeamUnit{
OrgID: ctx.Org.Team.OrgID,
Type: tp,
})
if len(form.Units) > 0 {
var units = make([]*models.TeamUnit, 0, len(form.Units))
unitTypes := models.FindUnitTypes(form.Units...)
for _, tp := range unitTypes {
units = append(units, &models.TeamUnit{
OrgID: ctx.Org.Team.OrgID,
Type: tp,
})
}
team.Units = units
}
team.Units = units
}

if err := models.UpdateTeam(team, isAuthChanged, isIncludeAllChanged); err != nil {
6543 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down