-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add link to user profile in markdown mention only if user exists #21533
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 all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9a2b465
Add link to user profile in markdown mention only if user exists
yardenshoham 5b0a692
Merge branch 'main' into mention-user-exists
yardenshoham 27dd534
Trigger build
yardenshoham 6fb9af9
Add user to tests
yardenshoham 459ce5b
fix test
yardenshoham 9589e70
Merge branch 'main' into mention-user-exists
yardenshoham a23d5a0
Fix TestSearchUsers
yardenshoham d2b211e
Drop db dependency
yardenshoham 52f4ad7
Merge remote-tracking branch 'upstream/main' into mention-user-exists
yardenshoham aab51ec
Fix test
yardenshoham f486a5f
refactor
wxiaoguang 2368ec8
Try to fix tests
yardenshoham 282869b
Update comment
yardenshoham 30c9ab0
Adjust tests
yardenshoham 2f7075d
Drop DB prep in tests
yardenshoham 42e9e96
fix tests
wxiaoguang d08bc56
oops, fix the lint
wxiaoguang b786f0e
Merge branch 'main' into mention-user-exists
lunny 3b7945e
Merge branch 'main' into mention-user-exists
lunny 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package markup | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/unittest" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
unittest.MainTest(m, &unittest.TestOptions{ | ||
GiteaRootPath: filepath.Join("..", ".."), | ||
FixtureFiles: []string{"user.yml"}, | ||
}) | ||
} |
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,29 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package markup | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models/user" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/markup" | ||
) | ||
|
||
func ProcessorHelper() *markup.ProcessorHelper { | ||
return &markup.ProcessorHelper{ | ||
IsUsernameMentionable: func(ctx context.Context, username string) bool { | ||
// TODO: cast ctx to modules/context.Context and use IsUserVisibleToViewer | ||
|
||
// Only link if the user actually exists | ||
userExists, err := user.IsUserExist(ctx, 0, username) | ||
if err != nil { | ||
log.Error("Failed to validate user in mention %q exists, assuming it does", username) | ||
userExists = true | ||
} | ||
return userExists | ||
}, | ||
} | ||
} |
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,20 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package markup | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/unittest" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestProcessorHelper(t *testing.T) { | ||
assert.NoError(t, unittest.PrepareTestDatabase()) | ||
assert.True(t, ProcessorHelper().IsUsernameMentionable(context.Background(), "user10")) | ||
assert.False(t, ProcessorHelper().IsUsernameMentionable(context.Background(), "no-such-user")) | ||
} |
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.