-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[Feature] Private README.md for organization #32872
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
784bedd
Use view as to get public and private profile repo
3682adb
make query string right
ef826a1
make sure the drop down appears only when criteria are met
6496b3c
Add hint for public and private profile repo name
changchaishi 4b3a8ac
fix that drop down manu shows in repository tab
changchaishi d71cba7
add check icons and translation
changchaishi 86e698d
add rollback to get private profile when view as is not present
changchaishi e95d716
Ignore view_as param when the profiles not both exist
changchaishi 48b4be2
adding profile test case
changchaishi 84ef527
use tw-hidden instead of display:none
changchaishi 0c70525
Merge branch 'main' into private-readme
wxiaoguang a47cf32
temp
wxiaoguang 586d304
temp
wxiaoguang 0202a09
refactor git repo usage
wxiaoguang 93e7a01
move view-as dropdown to sidebar
wxiaoguang ae3627f
clarify HasOrgProfileReadme vs HasUserProfileReadme, fix tests
wxiaoguang dc10881
fix comments
wxiaoguang db2c451
fix js
wxiaoguang b9b2701
fix mistake
wxiaoguang 873dc8f
improve tests
wxiaoguang c1ae1ad
auto toggle "private" checkbox by repo name
wxiaoguang 95312c7
make "view as" translatable
wxiaoguang bc5718d
fine tune "view as"
wxiaoguang 2c0e19d
Merge branch 'main' into private-readme
wxiaoguang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package integration | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
auth_model "code.gitea.io/gitea/models/auth" | ||
api "code.gitea.io/gitea/modules/structs" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func getCreateProfileReadmeFileOptions(profileType string) api.CreateFileOptions { | ||
content := fmt.Sprintf("# %s", profileType) | ||
contentEncoded := base64.StdEncoding.EncodeToString([]byte(content)) | ||
return api.CreateFileOptions{ | ||
FileOptions: api.FileOptions{ | ||
BranchName: "main", | ||
NewBranchName: "main", | ||
Message: "create the profile README.md", | ||
Dates: api.CommitDateOptions{ | ||
Author: time.Unix(946684810, 0), | ||
Committer: time.Unix(978307190, 0), | ||
}, | ||
}, | ||
ContentBase64: contentEncoded, | ||
} | ||
} | ||
|
||
func createTestProfile(t *testing.T, orgName, profileType string) { | ||
repoName := ".profile" | ||
isPrivate := false | ||
if profileType == "Private" { | ||
repoName = ".profile-private" | ||
isPrivate = true | ||
} | ||
|
||
ctx := NewAPITestContext(t, "user1", repoName, auth_model.AccessTokenScopeAll) | ||
session := loginUser(t, "user1") | ||
tokenAdmin := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeAll) | ||
|
||
// create repo | ||
t.Run("CreateOrganization"+profileType+"ProfileRepo", doAPICreateOrganizationRepository(ctx, orgName, &api.CreateRepoOption{ | ||
Name: repoName, | ||
Private: isPrivate, | ||
})) | ||
|
||
// create readme | ||
createFileOptions := getCreateProfileReadmeFileOptions(profileType) | ||
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", orgName, repoName, "README.md"), &createFileOptions). | ||
AddTokenAuth(tokenAdmin) | ||
MakeRequest(t, req, http.StatusCreated) | ||
} | ||
|
||
func TestOrgProfile(t *testing.T) { | ||
onGiteaRun(t, testOrgProfile) | ||
} | ||
|
||
func testOrgProfile(t *testing.T, u *url.URL) { | ||
// html #user-content-public (markdown title of public profile) | ||
// html #user-content-private (markdown title of private profile) | ||
// html #profile_view_as_dropdown (indicate whether the view as dropdown menu is present) | ||
|
||
// PART 1: Test Both Private and Public | ||
createTestProfile(t, "org3", "Public") | ||
createTestProfile(t, "org3", "Private") | ||
|
||
// Anonymous User | ||
req := NewRequest(t, "GET", "org3") | ||
resp := MakeRequest(t, req, http.StatusOK) | ||
htmlDoc := NewHTMLParser(t, resp.Body) | ||
|
||
profileDivs := htmlDoc.doc.Find("#user-content-public") | ||
assert.EqualValues(t, 1, profileDivs.Length()) | ||
|
||
dropDownDiv := htmlDoc.doc.Find("#profile_view_as_dropdown") | ||
assert.EqualValues(t, 0, dropDownDiv.Length()) | ||
|
||
// Logged in but not member | ||
session := loginUser(t, "user24") | ||
req = NewRequest(t, "GET", "org3") | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
|
||
profileDivs = htmlDoc.doc.Find("#user-content-public") | ||
assert.EqualValues(t, 1, profileDivs.Length()) | ||
|
||
dropDownDiv = htmlDoc.doc.Find("#profile_view_as_dropdown") | ||
assert.EqualValues(t, 0, dropDownDiv.Length()) | ||
|
||
// Site Admin | ||
session = loginUser(t, "user1") | ||
req = NewRequest(t, "GET", "org3") | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
|
||
profileDivs = htmlDoc.doc.Find("#user-content-public") | ||
assert.EqualValues(t, 1, profileDivs.Length()) | ||
|
||
dropDownDiv = htmlDoc.doc.Find("#profile_view_as_dropdown") | ||
assert.EqualValues(t, 1, dropDownDiv.Length()) | ||
|
||
req = NewRequest(t, "GET", "/org3?view_as=member") | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
|
||
profileDivs = htmlDoc.doc.Find("#user-content-private") | ||
assert.EqualValues(t, 1, profileDivs.Length()) | ||
|
||
req = NewRequest(t, "GET", "/org3?view_as=public") | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
|
||
profileDivs = htmlDoc.doc.Find("#user-content-public") | ||
assert.EqualValues(t, 1, profileDivs.Length()) | ||
|
||
// PART 2: Each org has either one of private pr public profile | ||
createTestProfile(t, "org41", "Public") | ||
createTestProfile(t, "org42", "Private") | ||
|
||
// Anonymous User | ||
req = NewRequest(t, "GET", "/org41") | ||
resp = MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
profileDivs = htmlDoc.doc.Find("#user-content-public") | ||
assert.EqualValues(t, 1, profileDivs.Length()) | ||
dropDownDiv = htmlDoc.doc.Find("#profile_view_as_dropdown") | ||
assert.EqualValues(t, 0, dropDownDiv.Length()) | ||
|
||
req = NewRequest(t, "GET", "/org42") | ||
resp = MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
profileDivs = htmlDoc.doc.Find("#user-content-public") | ||
assert.EqualValues(t, 0, profileDivs.Length()) | ||
profileDivs = htmlDoc.doc.Find("#user-content-public") | ||
assert.EqualValues(t, 0, profileDivs.Length()) | ||
dropDownDiv = htmlDoc.doc.Find("#profile_view_as_dropdown") | ||
assert.EqualValues(t, 0, dropDownDiv.Length()) | ||
|
||
// Site Admin | ||
req = NewRequest(t, "GET", "/org41") | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
profileDivs = htmlDoc.doc.Find("#user-content-public") | ||
assert.EqualValues(t, 1, profileDivs.Length()) | ||
dropDownDiv = htmlDoc.doc.Find("#profile_view_as_dropdown") | ||
assert.EqualValues(t, 0, dropDownDiv.Length()) | ||
|
||
req = NewRequest(t, "GET", "/org42") | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
profileDivs = htmlDoc.doc.Find("#user-content-private") | ||
assert.EqualValues(t, 1, profileDivs.Length()) | ||
dropDownDiv = htmlDoc.doc.Find("#profile_view_as_dropdown") | ||
assert.EqualValues(t, 0, dropDownDiv.Length()) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.