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

Improve behavior of "Fork" button #17288

Merged
merged 47 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3b641de
Improbe behaviour of fork button
qwerty287 Oct 11, 2021
24b83ee
Merge branch 'main' into fork-dialog
qwerty287 Oct 11, 2021
4a1facf
Apply suggestions from code review
qwerty287 Oct 11, 2021
97fb7bd
Remove old lines
qwerty287 Oct 11, 2021
c822b22
Apply suggestions
qwerty287 Oct 11, 2021
5bb9f9f
Fix test
qwerty287 Oct 11, 2021
859f69c
Merge branch 'main' into fork-dialog
qwerty287 Oct 11, 2021
265d9cf
Remove unnecessary or
qwerty287 Oct 11, 2021
128c2e6
Merge branch 'main' into fork-dialog
qwerty287 Oct 12, 2021
9dd9098
Merge branch 'main' into fork-dialog
6543 Oct 12, 2021
0a25a69
Merge branch 'main' into fork-dialog
qwerty287 Oct 15, 2021
eb261c5
Merge branch 'fork-dialog' of github.com:qwerty287/gitea into fork-di…
qwerty287 Oct 16, 2021
125c1c8
Merge branch 'main' into fork-dialog
qwerty287 Oct 16, 2021
01a6e67
Update templates/repo/header.tmpl
qwerty287 Oct 16, 2021
ad23347
Add comment
qwerty287 Oct 16, 2021
1a89f5d
Merge branch 'fork-dialog' of github.com:qwerty287/gitea into fork-di…
qwerty287 Oct 16, 2021
6f86036
Merge branch 'main' into fork-dialog
qwerty287 Oct 17, 2021
654738f
Merge branch 'main' into fork-dialog
qwerty287 Oct 21, 2021
4fc7b08
Merge branch 'main' into fork-dialog
wxiaoguang Oct 21, 2021
5d9c5f9
Merge branch 'main' into fork-dialog
qwerty287 Oct 22, 2021
af026cb
Merge branch 'main' into fork-dialog
qwerty287 Oct 23, 2021
ae7e9fa
Merge branch 'main' into fork-dialog
qwerty287 Oct 26, 2021
9667754
Merge branch 'main' into fork-dialog
qwerty287 Oct 28, 2021
4097805
Merge branch 'main' into fork-dialog
qwerty287 Nov 1, 2021
6a4ab3a
Merge branch 'main' into fork-dialog
qwerty287 Nov 7, 2021
be1bfba
Merge branch 'main' into fork-dialog
qwerty287 Nov 12, 2021
d094c23
Merge branch 'main' into fork-dialog
qwerty287 Nov 15, 2021
3917a02
Merge branch 'main' into fork-dialog
qwerty287 Nov 16, 2021
d02ee5c
Merge branch 'main' into fork-dialog
qwerty287 Nov 21, 2021
3968d00
Merge branch 'main' into fork-dialog
qwerty287 Nov 23, 2021
85149a9
Fix situation if you can't fork but don't have forks
qwerty287 Nov 23, 2021
f9f224d
Fix lint
qwerty287 Nov 23, 2021
34641cf
Merge branch 'main' into fork-dialog
qwerty287 Nov 25, 2021
75ce8ac
Apply changes from #17783
qwerty287 Nov 25, 2021
862d39a
fmt
qwerty287 Nov 25, 2021
73cc7e8
fmt
qwerty287 Nov 25, 2021
813ead4
Merge branch 'main' into fork-dialog
qwerty287 Nov 26, 2021
f87c0dc
Apply tweaks
qwerty287 Nov 27, 2021
6621589
Merge branch 'main' into fork-dialog
qwerty287 Nov 27, 2021
214651a
Merge branch 'main' into fork-dialog
qwerty287 Nov 29, 2021
43c0cfd
Merge branch 'main' into fork-dialog
qwerty287 Dec 5, 2021
7a6ec83
Merge branch 'main' into fork-dialog
wxiaoguang Dec 10, 2021
5b41a0a
Rm dupl css
qwerty287 Dec 11, 2021
bbb458f
Merge branch 'main' into fork-dialog
qwerty287 Dec 11, 2021
45d7872
Merge branch 'main' into fork-dialog
qwerty287 Dec 12, 2021
71dfc97
Fix build
qwerty287 Dec 12, 2021
c85aff6
Merge branch 'main' into fork-dialog
lunny Dec 13, 2021
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
29 changes: 29 additions & 0 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,35 @@ func (repo *Repository) CanUserFork(user *User) (bool, error) {
return false, nil
}

// GetForksByUserAndOwnedOrgs return forked repos of the user and owned orgs
func (repo *Repository) GetForksByUserAndOwnedOrgs(user *User) ([]*Repository, error) {
var repoList []*Repository
if user == nil {
return repoList, nil
}
var forkedRepo *Repository
forkedRepo, err := repo.GetUserFork(user.ID)
if err != nil {
return repoList, err
}
if forkedRepo != nil {
repoList = append(repoList, forkedRepo)
}
if err := user.GetOwnedOrganizations(); err != nil {
return repoList, err
}
for _, org := range user.OwnedOrgs {
forkedRepo, err := repo.GetUserFork(org.ID)
if err != nil {
return repoList, err
}
if forkedRepo != nil {
repoList = append(repoList, forkedRepo)
}
}
return repoList, nil
}

// CanUserDelete returns true if user could delete the repository
func (repo *Repository) CanUserDelete(user *User) (bool, error) {
if user.IsAdmin || user.ID == repo.OwnerID {
Expand Down
16 changes: 15 additions & 1 deletion modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,24 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
ctx.Data["CanWriteIssues"] = ctx.Repo.CanWrite(models.UnitTypeIssues)
ctx.Data["CanWritePulls"] = ctx.Repo.CanWrite(models.UnitTypePullRequests)

if ctx.Data["CanSignedUserFork"], err = ctx.Repo.Repository.CanUserFork(ctx.User); err != nil {
canSignedUserFork, err := ctx.Repo.Repository.CanUserFork(ctx.User)
if err != nil {
ctx.ServerError("CanUserFork", err)
return
}
ctx.Data["CanSignedUserFork"] = canSignedUserFork

userAndOrgForks, err := ctx.Repo.Repository.GetForksByUserAndOwnedOrgs(ctx.User)
if err != nil {
ctx.ServerError("GetForksByUserAndOwnedOrgs", err)
return
}
ctx.Data["UserAndOrgForks"] = userAndOrgForks

// canSignedUserFork is true if the current user doesn't have a fork of this repo yet or
// if he owns an org that doesn't have a fork of this repo yet
// If multiple forks are available or if the user can fork to another account, but there is already a fork: open selection dialog
ctx.Data["ShowForkModal"] = len(userAndOrgForks) > 1 || (canSignedUserFork && len(userAndOrgForks) > 0)

ctx.Data["DisableSSH"] = setting.SSH.Disabled
ctx.Data["ExposeAnonSSH"] = setting.SSH.ExposeAnonymous
Expand Down
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ visibility_fork_helper = (Changing this will affect all forks.)
clone_helper = Need help cloning? Visit <a target="_blank" rel="noopener noreferrer" href="%s">Help</a>.
fork_repo = Fork Repository
fork_from = Fork From
already_forked = You've already forked %s.
fork_to_different_account = Fork to a different account
fork_visibility_helper = The visibility of a forked repository cannot be changed.
use_template = Use this template
clone_in_vsc = Clone in VS Code
Expand Down
36 changes: 34 additions & 2 deletions templates/repo/header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,42 @@
</form>
{{end}}
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
<div class="ui labeled button{{if not $.CanSignedUserFork}} poping up disabled{{end}}"{{if and (not $.CanSignedUserFork) $.IsSigned}} data-content="{{$.i18n.Tr "repo.fork_from_self"}}" {{else if not $.IsSigned}} data-content="{{$.i18n.Tr "repo.fork_guest_user"}}"{{end}} data-position="top center" data-variation="tiny" tabindex="0">
<a class="ui compact small basic button"{{if $.CanSignedUserFork}} href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{end}}>
<div class="ui labeled button{{if or (not $.IsSigned)}} poping up disabled{{end}}" {{if not $.IsSigned}} data-content="{{$.i18n.Tr "repo.fork_guest_user"}}"{{end}} data-position="top center" data-variation="tiny" tabindex="0">
<a class="ui compact{{if $.ShowForkModal}} show-modal{{end}} small basic button"
{{if not $.CanSignedUserFork}}
{{if gt (len $.UserAndOrgForks) 1}}
data-modal="#fork-repo-modal"
{{else}}
href="{{AppSubUrl}}/{{(index $.UserAndOrgForks 0).FullName}}"
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
{{end}}
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
{{else if eq (len $.UserAndOrgForks) 0}}
href="{{AppSubUrl}}/repo/fork/{{.ID}}"
{{else}}
data-modal="#fork-repo-modal"
{{end}}
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
>
{{svg "octicon-repo-forked"}}{{$.i18n.Tr "repo.fork"}}
</a>
<div class="ui small modal" id="fork-repo-modal">
<div class="header">
{{$.i18n.Tr "repo.already_forked" .FullName}}
</div>
<div class="content">
{{range $.UserAndOrgForks}}
<div class="text left">
<a href="{{.Link}}">
{{svg "octicon-repo-forked"}}{{.FullName}}
</a>
</div>
{{end}}
{{if $.CanSignedUserFork}}
<br><br>
<a class="ui compact small button right actions" style="margin-bottom: 20px;" href="{{AppSubUrl}}/repo/fork/{{.ID}}">
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
{{$.i18n.Tr "repo.fork_to_different_account"}}
</a>
{{end}}
</div>
</div>
<a class="ui basic label" href="{{.Link}}/forks">
{{CountFmt .NumForks}}
</a>
Expand Down
3 changes: 2 additions & 1 deletion web_src/less/_repository.less
Original file line number Diff line number Diff line change
Expand Up @@ -2729,7 +2729,8 @@
#delete-repo-modal,
#delete-wiki-modal,
#convert-fork-repo-modal,
#convert-mirror-repo-modal {
#convert-mirror-repo-modal,
#fork-repo-modal {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just very curious to ask ... why do we need this css style? I use !important for only one or two times in all my projects, but I see !important in Gitea css code everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added another one, because every dialog/modal is listed in this css style... (but I don't know why there is this style)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the modal dialog work without this style? If it works alright, we can get rid of this strange styling ....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't work without this style

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important is needed because of semanatic/fomantic css that is not very though out and uses important all over the place so we also have to use important to style it :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anytime you need to override vendor CSS, it's a good idea to use !important. We should of course reduce unnecessary use, of which there are also a few cases.

Copy link
Member

@silverwind silverwind Oct 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there is a w-100 helper CSS class for width: 100% !important;, please use that instead.

.w-100 { width: 100% !important; }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silverwind If I remove the fork-repo-modal and add the w-100 class to the modal, it doesn't work (the content of the fork-repo-modal class is .ui.message { width: 100% !important; } and not width: 100% !important;)

.ui.message {
width: 100% !important;
}
Expand Down