loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request 'Allow changing global wiki editability via the API' (#3276) from algernon/forgejo:let-the-api-control-your-wiki-editability into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3276
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>

+97 -4
+3
modules/structs/repo.go
··· 89 89 HasWiki bool `json:"has_wiki"` 90 90 ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"` 91 91 WikiBranch string `json:"wiki_branch,omitempty"` 92 + GloballyEditableWiki bool `json:"globally_editable_wiki"` 92 93 HasPullRequests bool `json:"has_pull_requests"` 93 94 HasProjects bool `json:"has_projects"` 94 95 HasReleases bool `json:"has_releases"` ··· 185 186 HasWiki *bool `json:"has_wiki,omitempty"` 186 187 // set this structure to use external wiki instead of internal 187 188 ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"` 189 + // set the globally editable state of the wiki 190 + GloballyEditableWiki *bool `json:"globally_editable_wiki,omitempty"` 188 191 // sets the default branch for this repository. 189 192 DefaultBranch *string `json:"default_branch,omitempty"` 190 193 // sets the branch used for this repository's wiki.
+21 -3
routers/api/v1/repo/repo.go
··· 845 845 newHasWiki = *opts.HasWiki 846 846 } 847 847 if currHasWiki || newHasWiki { 848 + wikiPermissions := repo.MustGetUnit(ctx, unit_model.TypeWiki).DefaultPermissions 849 + if opts.GloballyEditableWiki != nil { 850 + if *opts.GloballyEditableWiki { 851 + wikiPermissions = repo_model.UnitAccessModeWrite 852 + } else { 853 + wikiPermissions = repo_model.UnitAccessModeRead 854 + } 855 + } 856 + 848 857 if newHasWiki && opts.ExternalWiki != nil && !unit_model.TypeExternalWiki.UnitGlobalDisabled() { 849 858 // Check that values are valid 850 859 if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) { ··· 864 873 } else if newHasWiki && opts.ExternalWiki == nil && !unit_model.TypeWiki.UnitGlobalDisabled() { 865 874 config := &repo_model.UnitConfig{} 866 875 units = append(units, repo_model.RepoUnit{ 867 - RepoID: repo.ID, 868 - Type: unit_model.TypeWiki, 869 - Config: config, 876 + RepoID: repo.ID, 877 + Type: unit_model.TypeWiki, 878 + Config: config, 879 + DefaultPermissions: wikiPermissions, 870 880 }) 871 881 deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki) 872 882 } else if !newHasWiki { ··· 876 886 if !unit_model.TypeWiki.UnitGlobalDisabled() { 877 887 deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeWiki) 878 888 } 889 + } else if *opts.GloballyEditableWiki { 890 + config := &repo_model.UnitConfig{} 891 + units = append(units, repo_model.RepoUnit{ 892 + RepoID: repo.ID, 893 + Type: unit_model.TypeWiki, 894 + Config: config, 895 + DefaultPermissions: wikiPermissions, 896 + }) 879 897 } 880 898 } 881 899
+6 -1
services/convert/repository.go
··· 77 77 } 78 78 } 79 79 hasWiki := false 80 + globallyEditableWiki := false 80 81 var externalWiki *api.ExternalWiki 81 - if _, err := repo.GetUnit(ctx, unit_model.TypeWiki); err == nil { 82 + if wikiUnit, err := repo.GetUnit(ctx, unit_model.TypeWiki); err == nil { 82 83 hasWiki = true 84 + if wikiUnit.DefaultPermissions == repo_model.UnitAccessModeWrite { 85 + globallyEditableWiki = true 86 + } 83 87 } else if unit, err := repo.GetUnit(ctx, unit_model.TypeExternalWiki); err == nil { 84 88 hasWiki = true 85 89 config := unit.ExternalWikiConfig() ··· 211 215 InternalTracker: internalTracker, 212 216 HasWiki: hasWiki, 213 217 WikiBranch: repo.WikiBranch, 218 + GloballyEditableWiki: globallyEditableWiki, 214 219 HasProjects: hasProjects, 215 220 HasReleases: hasReleases, 216 221 HasPackages: hasPackages,
+9
templates/swagger/v1_json.tmpl
··· 20835 20835 "external_wiki": { 20836 20836 "$ref": "#/definitions/ExternalWiki" 20837 20837 }, 20838 + "globally_editable_wiki": { 20839 + "description": "set the globally editable state of the wiki", 20840 + "type": "boolean", 20841 + "x-go-name": "GloballyEditableWiki" 20842 + }, 20838 20843 "has_actions": { 20839 20844 "description": "either `true` to enable actions unit, or `false` to disable them.", 20840 20845 "type": "boolean", ··· 23748 23753 "full_name": { 23749 23754 "type": "string", 23750 23755 "x-go-name": "FullName" 23756 + }, 23757 + "globally_editable_wiki": { 23758 + "type": "boolean", 23759 + "x-go-name": "GloballyEditableWiki" 23751 23760 }, 23752 23761 "has_actions": { 23753 23762 "type": "boolean",
+58
tests/integration/api_wiki_test.go
··· 15 15 repo_model "code.gitea.io/gitea/models/repo" 16 16 unit_model "code.gitea.io/gitea/models/unit" 17 17 "code.gitea.io/gitea/models/unittest" 18 + user_model "code.gitea.io/gitea/models/user" 18 19 api "code.gitea.io/gitea/modules/structs" 19 20 repo_service "code.gitea.io/gitea/services/repository" 20 21 "code.gitea.io/gitea/tests" ··· 284 285 285 286 // Creating a new Wiki page on user2's repo works now 286 287 testCreateWiki(http.StatusCreated) 288 + } 289 + 290 + func TestAPISetWikiGlobalEditability(t *testing.T) { 291 + defer tests.PrepareTestEnv(t)() 292 + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user2"}) 293 + session := loginUser(t, user.Name) 294 + token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) 295 + 296 + // Create a new repository for testing purposes 297 + repo, _, f := CreateDeclarativeRepo(t, user, "", []unit_model.Type{ 298 + unit_model.TypeCode, 299 + unit_model.TypeWiki, 300 + }, nil, nil) 301 + defer f() 302 + urlStr := fmt.Sprintf("/api/v1/repos/%s", repo.FullName()) 303 + 304 + assertGlobalEditability := func(t *testing.T, editability bool) { 305 + t.Helper() 306 + 307 + req := NewRequest(t, "GET", urlStr) 308 + resp := MakeRequest(t, req, http.StatusOK) 309 + 310 + var opts api.Repository 311 + DecodeJSON(t, resp, &opts) 312 + 313 + assert.Equal(t, opts.GloballyEditableWiki, editability) 314 + } 315 + 316 + t.Run("api includes GloballyEditableWiki", func(t *testing.T) { 317 + defer tests.PrintCurrentTest(t)() 318 + 319 + assertGlobalEditability(t, false) 320 + }) 321 + 322 + t.Run("api can turn on GloballyEditableWiki", func(t *testing.T) { 323 + defer tests.PrintCurrentTest(t)() 324 + 325 + globallyEditable := true 326 + req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditRepoOption{ 327 + GloballyEditableWiki: &globallyEditable, 328 + }).AddTokenAuth(token) 329 + MakeRequest(t, req, http.StatusOK) 330 + 331 + assertGlobalEditability(t, true) 332 + }) 333 + 334 + t.Run("disabling the wiki disables GloballyEditableWiki", func(t *testing.T) { 335 + defer tests.PrintCurrentTest(t)() 336 + 337 + hasWiki := false 338 + req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditRepoOption{ 339 + HasWiki: &hasWiki, 340 + }).AddTokenAuth(token) 341 + MakeRequest(t, req, http.StatusOK) 342 + 343 + assertGlobalEditability(t, false) 344 + }) 287 345 } 288 346 289 347 func TestAPIListPageRevisions(t *testing.T) {