Browse Source

Remove unit types commits and settings (#2161)

* Remove unit types commits and settings

* Can not limit units in administrator teams

* Limit changing units only to teams with read and write access mode

* Small code optimization
Lauris BH 1 year ago
parent
commit
f33e6ae09e

+ 1 - 1
integrations/repo_test.go

@@ -39,7 +39,7 @@ func TestViewRepo3(t *testing.T) {
39 39
 	prepareTestEnv(t)
40 40
 
41 41
 	req := NewRequest(t, "GET", "/user3/repo3")
42
-	session := loginUser(t, "user3")
42
+	session := loginUser(t, "user4")
43 43
 	session.MakeRequest(t, req, http.StatusOK)
44 44
 }
45 45
 

+ 2 - 2
models/access_test.go

@@ -21,7 +21,7 @@ func TestAccessLevel(t *testing.T) {
21 21
 	assert.NoError(t, PrepareTestDatabase())
22 22
 
23 23
 	user1 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
24
-	user2 := AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
24
+	user2 := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
25 25
 	repo1 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 2, IsPrivate: false}).(*Repository)
26 26
 	repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository)
27 27
 
@@ -46,7 +46,7 @@ func TestHasAccess(t *testing.T) {
46 46
 	assert.NoError(t, PrepareTestDatabase())
47 47
 
48 48
 	user1 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
49
-	user2 := AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
49
+	user2 := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
50 50
 	repo1 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 2, IsPrivate: false}).(*Repository)
51 51
 	repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository)
52 52
 

+ 6 - 0
models/fixtures/access.yml

@@ -9,3 +9,9 @@
9 9
   user_id: 4
10 10
   repo_id: 4
11 11
   mode: 2 # write
12
+
13
+-
14
+  id: 3
15
+  user_id: 4
16
+  repo_id: 3
17
+  mode: 2 # write

+ 12 - 12
models/fixtures/repo_unit.yml

@@ -10,7 +10,7 @@
10 10
   id: 2
11 11
   repo_id: 1
12 12
   type: 2
13
-  index: 0
13
+  index: 1
14 14
   config: "{}"
15 15
   created_unix: 946684810
16 16
 
@@ -18,23 +18,23 @@
18 18
   id: 3
19 19
   repo_id: 1
20 20
   type: 3
21
-  index: 0
21
+  index: 2
22 22
   config: "{}"
23 23
   created_unix: 946684810
24 24
 
25 25
 -
26 26
   id: 4
27 27
   repo_id: 1
28
-  type: 5
29
-  index: 0
28
+  type: 4
29
+  index: 3
30 30
   config: "{}"
31 31
   created_unix: 946684810
32 32
 
33 33
 -
34 34
   id: 5
35 35
   repo_id: 1
36
-  type: 7
37
-  index: 0
36
+  type: 5
37
+  index: 4
38 38
   config: "{}"
39 39
   created_unix: 946684810
40 40
 
@@ -50,7 +50,7 @@
50 50
   id: 7
51 51
   repo_id: 3
52 52
   type: 2
53
-  index: 0
53
+  index: 1
54 54
   config: "{}"
55 55
   created_unix: 946684810
56 56
 
@@ -58,22 +58,22 @@
58 58
   id: 8
59 59
   repo_id: 3
60 60
   type: 3
61
-  index: 0
61
+  index: 2
62 62
   config: "{}"
63 63
   created_unix: 946684810
64 64
 
65 65
 -
66 66
   id: 9
67 67
   repo_id: 3
68
-  type: 5
69
-  index: 0
68
+  type: 4
69
+  index: 3
70 70
   config: "{}"
71 71
   created_unix: 946684810
72 72
 
73 73
 -
74 74
   id: 10
75 75
   repo_id: 3
76
-  type: 7
77
-  index: 0
76
+  type: 5
77
+  index: 4
78 78
   config: "{}"
79 79
   created_unix: 946684810

+ 4 - 4
models/fixtures/team.yml

@@ -6,7 +6,7 @@
6 6
   authorize: 4 # owner
7 7
   num_repos: 2
8 8
   num_members: 1
9
-  unit_types: '[1,2,3,4,5,6,7,8,9]'
9
+  unit_types: '[1,2,3,4,5,6,7]'
10 10
 
11 11
 -
12 12
   id: 2
@@ -16,7 +16,7 @@
16 16
   authorize: 2 # write
17 17
   num_repos: 1
18 18
   num_members: 2
19
-  unit_types: '[1,2,3,4,5,6,7,8,9]'
19
+  unit_types: '[1,2,3,4,5,6,7]'
20 20
 
21 21
 -
22 22
   id: 3
@@ -26,7 +26,7 @@
26 26
   authorize: 4 # owner
27 27
   num_repos: 0
28 28
   num_members: 1
29
-  unit_types: '[1,2,3,4,5,6,7,8,9]'
29
+  unit_types: '[1,2,3,4,5,6,7]'
30 30
 
31 31
 -
32 32
   id: 4
@@ -36,4 +36,4 @@
36 36
   authorize: 4 # owner
37 37
   num_repos: 0
38 38
   num_members: 1
39
-  unit_types: '[1,2,3,4,5,6,7,8,9]'
39
+  unit_types: '[1,2,3,4,5,6,7]'

+ 2 - 0
models/migrations/migrations.go

@@ -124,6 +124,8 @@ var migrations = []Migration{
124 124
 	NewMigration("regenerate git hooks", regenerateGitHooks36),
125 125
 	// v37 -> v38
126 126
 	NewMigration("unescape user full names", unescapeUserFullNames),
127
+	// v38 -> v39
128
+	NewMigration("remove commits and settings unit types", removeCommitsUnitType),
127 129
 }
128 130
 
129 131
 // Migrate database to current version

+ 16 - 16
models/migrations/v16.go

@@ -26,15 +26,15 @@ type RepoUnit struct {
26 26
 
27 27
 // Enumerate all the unit types
28 28
 const (
29
-	UnitTypeCode            = iota + 1 // 1 code
30
-	UnitTypeIssues                     // 2 issues
31
-	UnitTypePRs                        // 3 PRs
32
-	UnitTypeCommits                    // 4 Commits
33
-	UnitTypeReleases                   // 5 Releases
34
-	UnitTypeWiki                       // 6 Wiki
35
-	UnitTypeSettings                   // 7 Settings
36
-	UnitTypeExternalWiki               // 8 ExternalWiki
37
-	UnitTypeExternalTracker            // 9 ExternalTracker
29
+	V16UnitTypeCode            = iota + 1 // 1 code
30
+	V16UnitTypeIssues                     // 2 issues
31
+	V16UnitTypePRs                        // 3 PRs
32
+	V16UnitTypeCommits                    // 4 Commits
33
+	V16UnitTypeReleases                   // 5 Releases
34
+	V16UnitTypeWiki                       // 6 Wiki
35
+	V16UnitTypeSettings                   // 7 Settings
36
+	V16UnitTypeExternalWiki               // 8 ExternalWiki
37
+	V16UnitTypeExternalTracker            // 9 ExternalTracker
38 38
 )
39 39
 
40 40
 // Repo describes a repository
@@ -79,32 +79,32 @@ func addUnitsToTables(x *xorm.Engine) error {
79 79
 
80 80
 	for _, repo := range repos {
81 81
 		for i := 1; i <= 9; i++ {
82
-			if (i == UnitTypeWiki || i == UnitTypeExternalWiki) && !repo.EnableWiki {
82
+			if (i == V16UnitTypeWiki || i == V16UnitTypeExternalWiki) && !repo.EnableWiki {
83 83
 				continue
84 84
 			}
85
-			if i == UnitTypeExternalWiki && !repo.EnableExternalWiki {
85
+			if i == V16UnitTypeExternalWiki && !repo.EnableExternalWiki {
86 86
 				continue
87 87
 			}
88
-			if i == UnitTypePRs && !repo.EnablePulls {
88
+			if i == V16UnitTypePRs && !repo.EnablePulls {
89 89
 				continue
90 90
 			}
91
-			if (i == UnitTypeIssues || i == UnitTypeExternalTracker) && !repo.EnableIssues {
91
+			if (i == V16UnitTypeIssues || i == V16UnitTypeExternalTracker) && !repo.EnableIssues {
92 92
 				continue
93 93
 			}
94
-			if i == UnitTypeExternalTracker && !repo.EnableExternalTracker {
94
+			if i == V16UnitTypeExternalTracker && !repo.EnableExternalTracker {
95 95
 				continue
96 96
 			}
97 97
 
98 98
 			var config = make(map[string]string)
99 99
 			switch i {
100
-			case UnitTypeExternalTracker:
100
+			case V16UnitTypeExternalTracker:
101 101
 				config["ExternalTrackerURL"] = repo.ExternalTrackerURL
102 102
 				config["ExternalTrackerFormat"] = repo.ExternalTrackerFormat
103 103
 				if len(repo.ExternalTrackerStyle) == 0 {
104 104
 					repo.ExternalTrackerStyle = markdown.IssueNameStyleNumeric
105 105
 				}
106 106
 				config["ExternalTrackerStyle"] = repo.ExternalTrackerStyle
107
-			case UnitTypeExternalWiki:
107
+			case V16UnitTypeExternalWiki:
108 108
 				config["ExternalWikiURL"] = repo.ExternalWikiURL
109 109
 			}
110 110
 

+ 56 - 0
models/migrations/v38.go

@@ -0,0 +1,56 @@
1
+// Copyright 2017 The Gitea Authors. All rights reserved.
2
+// Use of this source code is governed by a MIT-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package migrations
6
+
7
+import (
8
+	"code.gitea.io/gitea/models"
9
+
10
+	"github.com/go-xorm/xorm"
11
+)
12
+
13
+func removeCommitsUnitType(x *xorm.Engine) (err error) {
14
+	// Update team unit types
15
+	const batchSize = 100
16
+	for start := 0; ; start += batchSize {
17
+		teams := make([]*models.Team, 0, batchSize)
18
+		if err := x.Limit(batchSize, start).Find(&teams); err != nil {
19
+			return err
20
+		}
21
+		if len(teams) == 0 {
22
+			break
23
+		}
24
+		for _, team := range teams {
25
+			ut := make([]models.UnitType, 0, len(team.UnitTypes))
26
+			for _, u := range team.UnitTypes {
27
+				if u < V16UnitTypeCommits {
28
+					ut = append(ut, u)
29
+				} else if u > V16UnitTypeSettings {
30
+					ut = append(ut, u-2)
31
+				} else if u > V16UnitTypeCommits && u != V16UnitTypeSettings {
32
+					ut = append(ut, u-1)
33
+				}
34
+			}
35
+			team.UnitTypes = ut
36
+			if _, err := x.Id(team.ID).Cols("unit_types").Update(team); err != nil {
37
+				return err
38
+			}
39
+		}
40
+	}
41
+
42
+	// Delete commits and settings unit types
43
+	if _, err = x.In("`type`", []models.UnitType{V16UnitTypeCommits, V16UnitTypeSettings}).Delete(new(RepoUnit)); err != nil {
44
+		return err
45
+	}
46
+	// Fix renumber unit types that where in enumeration after settings unit type
47
+	if _, err = x.Where("`type` > ?", V16UnitTypeSettings).Decr("type").Decr("index").Update(new(RepoUnit)); err != nil {
48
+		return err
49
+	}
50
+	// Fix renumber unit types that where in enumeration after commits unit type
51
+	if _, err = x.Where("`type` > ?", V16UnitTypeCommits).Decr("type").Decr("index").Update(new(RepoUnit)); err != nil {
52
+		return err
53
+	}
54
+
55
+	return nil
56
+}

+ 4 - 0
models/repo.go

@@ -377,6 +377,10 @@ func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) (
377 377
 
378 378
 	var allTypes = make(map[UnitType]struct{}, len(allRepUnitTypes))
379 379
 	for _, team := range teams {
380
+		// Administrators can not be limited
381
+		if team.Authorize >= AccessModeAdmin {
382
+			return nil
383
+		}
380 384
 		for _, unitType := range team.UnitTypes {
381 385
 			allTypes[unitType] = struct{}{}
382 386
 		}

+ 2 - 7
models/repo_unit.go

@@ -75,8 +75,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
75 75
 	switch colName {
76 76
 	case "type":
77 77
 		switch UnitType(Cell2Int64(val)) {
78
-		case UnitTypeCode, UnitTypeIssues, UnitTypePullRequests, UnitTypeCommits, UnitTypeReleases,
79
-			UnitTypeWiki, UnitTypeSettings:
78
+		case UnitTypeCode, UnitTypeIssues, UnitTypePullRequests, UnitTypeReleases,
79
+			UnitTypeWiki:
80 80
 			r.Config = new(UnitConfig)
81 81
 		case UnitTypeExternalWiki:
82 82
 			r.Config = new(ExternalWikiConfig)
@@ -116,11 +116,6 @@ func (r *RepoUnit) PullRequestsConfig() *UnitConfig {
116 116
 	return r.Config.(*UnitConfig)
117 117
 }
118 118
 
119
-// CommitsConfig returns config for UnitTypeCommits
120
-func (r *RepoUnit) CommitsConfig() *UnitConfig {
121
-	return r.Config.(*UnitConfig)
122
-}
123
-
124 119
 // ReleasesConfig returns config for UnitTypeReleases
125 120
 func (r *RepoUnit) ReleasesConfig() *UnitConfig {
126 121
 	return r.Config.(*UnitConfig)

+ 10 - 36
models/unit.go

@@ -12,12 +12,10 @@ const (
12 12
 	UnitTypeCode            UnitType = iota + 1 // 1 code
13 13
 	UnitTypeIssues                              // 2 issues
14 14
 	UnitTypePullRequests                        // 3 PRs
15
-	UnitTypeCommits                             // 4 Commits
16
-	UnitTypeReleases                            // 5 Releases
17
-	UnitTypeWiki                                // 6 Wiki
18
-	UnitTypeSettings                            // 7 Settings
19
-	UnitTypeExternalWiki                        // 8 ExternalWiki
20
-	UnitTypeExternalTracker                     // 9 ExternalTracker
15
+	UnitTypeReleases                            // 4 Releases
16
+	UnitTypeWiki                                // 5 Wiki
17
+	UnitTypeExternalWiki                        // 6 ExternalWiki
18
+	UnitTypeExternalTracker                     // 7 ExternalTracker
21 19
 )
22 20
 
23 21
 var (
@@ -26,10 +24,8 @@ var (
26 24
 		UnitTypeCode,
27 25
 		UnitTypeIssues,
28 26
 		UnitTypePullRequests,
29
-		UnitTypeCommits,
30 27
 		UnitTypeReleases,
31 28
 		UnitTypeWiki,
32
-		UnitTypeSettings,
33 29
 		UnitTypeExternalWiki,
34 30
 		UnitTypeExternalTracker,
35 31
 	}
@@ -39,22 +35,18 @@ var (
39 35
 		UnitTypeCode,
40 36
 		UnitTypeIssues,
41 37
 		UnitTypePullRequests,
42
-		UnitTypeCommits,
43 38
 		UnitTypeReleases,
44 39
 		UnitTypeWiki,
45
-		UnitTypeSettings,
46 40
 	}
47 41
 
48
-	// MustRepoUnits contains the units could be disabled currently
42
+	// MustRepoUnits contains the units could not be disabled currently
49 43
 	MustRepoUnits = []UnitType{
50 44
 		UnitTypeCode,
51
-		UnitTypeCommits,
52 45
 		UnitTypeReleases,
53
-		UnitTypeSettings,
54 46
 	}
55 47
 )
56 48
 
57
-// Unit is a tab page of one repository
49
+// Unit is a section of one repository
58 50
 type Unit struct {
59 51
 	Type    UnitType
60 52
 	NameKey string
@@ -65,7 +57,7 @@ type Unit struct {
65 57
 
66 58
 // CanDisable returns if this unit could be disabled.
67 59
 func (u *Unit) CanDisable() bool {
68
-	return u.Type != UnitTypeSettings
60
+	return true
69 61
 }
70 62
 
71 63
 // Enumerate all the units
@@ -102,20 +94,12 @@ var (
102 94
 		2,
103 95
 	}
104 96
 
105
-	UnitCommits = Unit{
106
-		UnitTypeCommits,
107
-		"repo.commits",
108
-		"/commits/master",
109
-		"repo.commits.desc",
110
-		3,
111
-	}
112
-
113 97
 	UnitReleases = Unit{
114 98
 		UnitTypeReleases,
115 99
 		"repo.releases",
116 100
 		"/releases",
117 101
 		"repo.releases.desc",
118
-		4,
102
+		3,
119 103
 	}
120 104
 
121 105
 	UnitWiki = Unit{
@@ -123,7 +107,7 @@ var (
123 107
 		"repo.wiki",
124 108
 		"/wiki",
125 109
 		"repo.wiki.desc",
126
-		5,
110
+		4,
127 111
 	}
128 112
 
129 113
 	UnitExternalWiki = Unit{
@@ -131,15 +115,7 @@ var (
131 115
 		"repo.ext_wiki",
132 116
 		"/wiki",
133 117
 		"repo.ext_wiki.desc",
134
-		5,
135
-	}
136
-
137
-	UnitSettings = Unit{
138
-		UnitTypeSettings,
139
-		"repo.settings",
140
-		"/settings",
141
-		"repo.settings.desc",
142
-		6,
118
+		4,
143 119
 	}
144 120
 
145 121
 	// Units contains all the units
@@ -148,10 +124,8 @@ var (
148 124
 		UnitTypeIssues:          UnitIssues,
149 125
 		UnitTypeExternalTracker: UnitExternalTracker,
150 126
 		UnitTypePullRequests:    UnitPullRequests,
151
-		UnitTypeCommits:         UnitCommits,
152 127
 		UnitTypeReleases:        UnitReleases,
153 128
 		UnitTypeWiki:            UnitWiki,
154 129
 		UnitTypeExternalWiki:    UnitExternalWiki,
155
-		UnitTypeSettings:        UnitSettings,
156 130
 	}
157 131
 )

+ 3 - 2
modules/context/repo.go

@@ -348,6 +348,9 @@ func RepoAssignment() macaron.Handler {
348 348
 					ctx.Repo.PullRequest.HeadInfo = ctx.Repo.BranchName
349 349
 				}
350 350
 			}
351
+
352
+			// Reset repo units as otherwise user specific units wont be loaded later
353
+			ctx.Repo.Repository.Units = nil
351 354
 		}
352 355
 		ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest
353 356
 
@@ -549,10 +552,8 @@ func UnitTypes() macaron.Handler {
549 552
 		ctx.Data["UnitTypeCode"] = models.UnitTypeCode
550 553
 		ctx.Data["UnitTypeIssues"] = models.UnitTypeIssues
551 554
 		ctx.Data["UnitTypePullRequests"] = models.UnitTypePullRequests
552
-		ctx.Data["UnitTypeCommits"] = models.UnitTypeCommits
553 555
 		ctx.Data["UnitTypeReleases"] = models.UnitTypeReleases
554 556
 		ctx.Data["UnitTypeWiki"] = models.UnitTypeWiki
555
-		ctx.Data["UnitTypeSettings"] = models.UnitTypeSettings
556 557
 		ctx.Data["UnitTypeExternalWiki"] = models.UnitTypeExternalWiki
557 558
 		ctx.Data["UnitTypeExternalTracker"] = models.UnitTypeExternalTracker
558 559
 	}

+ 1 - 0
options/locale/locale_en-US.ini

@@ -251,6 +251,7 @@ username_been_taken = Username already taken.
251 251
 repo_name_been_taken = Repository name already used.
252 252
 org_name_been_taken = Organization name already taken.
253 253
 team_name_been_taken = Team name already taken.
254
+team_no_units_error = Team must have at least one unit enabled.
254 255
 email_been_used = Email already used.
255 256
 openid_been_used = OpenID address '%s' already used.
256 257
 username_password_incorrect = Incorrect username or password.

+ 3 - 0
public/css/index.css

@@ -1202,6 +1202,9 @@ footer .ui.language .menu {
1202 1202
   margin-top: -1px;
1203 1203
   font-size: 15px;
1204 1204
 }
1205
+.repository .tabs .navbar {
1206
+  justify-content: initial;
1207
+}
1205 1208
 .repository .navbar {
1206 1209
   display: flex;
1207 1210
   justify-content: space-between;

+ 13 - 0
public/js/index.js

@@ -657,6 +657,18 @@ function initRepositoryCollaboration() {
657 657
     });
658 658
 }
659 659
 
660
+function initTeamSettings() {
661
+    // Change team access mode
662
+    $('.organization.new.team input[name=permission]').change(function () {
663
+        var val = $('input[name=permission]:checked', '.organization.new.team').val()
664
+        if (val === 'admin') {
665
+            $('.organization.new.team .team-units').hide();
666
+        } else {
667
+            $('.organization.new.team .team-units').show();
668
+        }
669
+    });
670
+}
671
+
660 672
 function initWikiForm() {
661 673
     var $editArea = $('.repository.wiki textarea#edit_area');
662 674
     if ($editArea.length > 0) {
@@ -1557,6 +1569,7 @@ $(document).ready(function () {
1557 1569
     initAdmin();
1558 1570
     initCodeView();
1559 1571
     initDashboardSearch();
1572
+    initTeamSettings();
1560 1573
 
1561 1574
     // Repo clone url.
1562 1575
     if ($('#repo-clone-url').length > 0) {

+ 6 - 0
public/less/_repository.less

@@ -36,6 +36,12 @@
36 36
 		}
37 37
 	}
38 38
 
39
+	.tabs {
40
+		.navbar {
41
+			justify-content: initial;
42
+		}
43
+	}
44
+
39 45
 	.navbar {
40 46
 		display: flex;
41 47
 		justify-content: space-between;

+ 28 - 19
routers/org/teams.go

@@ -171,14 +171,18 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
171 171
 	ctx.Data["Title"] = ctx.Org.Organization.FullName
172 172
 	ctx.Data["PageIsOrgTeams"] = true
173 173
 	ctx.Data["PageIsOrgTeamsNew"] = true
174
+	ctx.Data["Units"] = models.Units
174 175
 
175 176
 	t := &models.Team{
176 177
 		OrgID:       ctx.Org.Organization.ID,
177 178
 		Name:        form.TeamName,
178 179
 		Description: form.Description,
179 180
 		Authorize:   models.ParseAccessMode(form.Permission),
180
-		UnitTypes:   form.Units,
181 181
 	}
182
+	if t.Authorize < models.AccessModeAdmin {
183
+		t.UnitTypes = form.Units
184
+	}
185
+
182 186
 	ctx.Data["Team"] = t
183 187
 
184 188
 	if ctx.HasError() {
@@ -186,6 +190,11 @@ func NewTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
186 190
 		return
187 191
 	}
188 192
 
193
+	if t.Authorize < models.AccessModeAdmin && len(form.Units) == 0 {
194
+		ctx.RenderWithErr(ctx.Tr("form.team_no_units_error"), tplTeamNew, &form)
195
+		return
196
+	}
197
+
189 198
 	if err := models.NewTeam(t); err != nil {
190 199
 		ctx.Data["Err_TeamName"] = true
191 200
 		switch {
@@ -238,27 +247,12 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
238 247
 	ctx.Data["Title"] = ctx.Org.Organization.FullName
239 248
 	ctx.Data["PageIsOrgTeams"] = true
240 249
 	ctx.Data["Team"] = t
241
-
242
-	if ctx.HasError() {
243
-		ctx.HTML(200, tplTeamNew)
244
-		return
245
-	}
250
+	ctx.Data["Units"] = models.Units
246 251
 
247 252
 	isAuthChanged := false
248 253
 	if !t.IsOwnerTeam() {
249 254
 		// Validate permission level.
250
-		var auth models.AccessMode
251
-		switch form.Permission {
252
-		case "read":
253
-			auth = models.AccessModeRead
254
-		case "write":
255
-			auth = models.AccessModeWrite
256
-		case "admin":
257
-			auth = models.AccessModeAdmin
258
-		default:
259
-			ctx.Error(401)
260
-			return
261
-		}
255
+		auth := models.ParseAccessMode(form.Permission)
262 256
 
263 257
 		t.Name = form.TeamName
264 258
 		if t.Authorize != auth {
@@ -267,7 +261,22 @@ func EditTeamPost(ctx *context.Context, form auth.CreateTeamForm) {
267 261
 		}
268 262
 	}
269 263
 	t.Description = form.Description
270
-	t.UnitTypes = form.Units
264
+	if t.Authorize < models.AccessModeAdmin {
265
+		t.UnitTypes = form.Units
266
+	} else {
267
+		t.UnitTypes = nil
268
+	}
269
+
270
+	if ctx.HasError() {
271
+		ctx.HTML(200, tplTeamNew)
272
+		return
273
+	}
274
+
275
+	if t.Authorize < models.AccessModeAdmin && len(form.Units) == 0 {
276
+		ctx.RenderWithErr(ctx.Tr("form.team_no_units_error"), tplTeamNew, &form)
277
+		return
278
+	}
279
+
271 280
 	if err := models.UpdateTeam(t, isAuthChanged); err != nil {
272 281
 		ctx.Data["Err_TeamName"] = true
273 282
 		switch {

+ 2 - 2
routers/routes/routes.go

@@ -450,8 +450,8 @@ func RegisterRoutes(m *macaron.Macaron) {
450 450
 
451 451
 		}, func(ctx *context.Context) {
452 452
 			ctx.Data["PageIsSettings"] = true
453
-		}, context.UnitTypes(), context.LoadRepoUnits(), context.CheckUnit(models.UnitTypeSettings))
454
-	}, reqSignIn, context.RepoAssignment(), reqRepoAdmin, context.RepoRef())
453
+		})
454
+	}, reqSignIn, context.RepoAssignment(), reqRepoAdmin, context.UnitTypes(), context.LoadRepoUnits(), context.RepoRef())
455 455
 
456 456
 	m.Get("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), repo.Action)
457 457
 

+ 2 - 2
templates/org/team/new.tmpl

@@ -50,9 +50,8 @@
50 50
 							</div>
51 51
 						</div>
52 52
 						<div class="ui divider"></div>
53
-					{{end}}
54 53
 
55
-					<div class="required grouped field">
54
+						<div class="team-units required grouped field"{{if eq .Team.Authorize 3}} style="display: none"{{end}}>
56 55
 							<label>{{.i18n.Tr "org.team_unit_desc"}}</label>
57 56
 							<br>
58 57
 							{{range $t, $unit := $.Units}}
@@ -66,6 +65,7 @@
66 65
 							{{end}}
67 66
 						</div>
68 67
 						<div class="ui divider"></div>
68
+					{{end}}
69 69
 
70 70
 					<div class="field">
71 71
 						{{if .PageIsOrgTeamsNew}}

+ 1 - 1
templates/repo/header.tmpl

@@ -73,7 +73,7 @@
73 73
 				</a>
74 74
 			{{end}}
75 75
 
76
-			{{if and (.Repository.EnableUnit $.UnitTypeCommits) (not .IsBareRepo)}}
76
+			{{if and (.Repository.EnableUnit $.UnitTypeCode) (not .IsBareRepo)}}
77 77
 			<a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}">
78 78
 				<i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span>
79 79
 			</a>