Skip to content

Commit 1ab5938

Browse files
authored
Hide/disable unusable UI elements when a repository is archived (#33459)
And by the way, remove some jQuery code
1 parent 0e8738b commit 1ab5938

File tree

5 files changed

+68
-67
lines changed

5 files changed

+68
-67
lines changed

models/issues/review.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -930,17 +930,19 @@ func MarkConversation(ctx context.Context, comment *Comment, doer *user_model.Us
930930
}
931931

932932
// CanMarkConversation Add or remove Conversation mark for a code comment permission check
933-
// the PR writer , offfcial reviewer and poster can do it
933+
// the PR writer , official reviewer and poster can do it
934934
func CanMarkConversation(ctx context.Context, issue *Issue, doer *user_model.User) (permResult bool, err error) {
935935
if doer == nil || issue == nil {
936936
return false, fmt.Errorf("issue or doer is nil")
937937
}
938938

939+
if err = issue.LoadRepo(ctx); err != nil {
940+
return false, err
941+
}
942+
if issue.Repo.IsArchived {
943+
return false, nil
944+
}
939945
if doer.ID != issue.PosterID {
940-
if err = issue.LoadRepo(ctx); err != nil {
941-
return false, err
942-
}
943-
944946
p, err := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
945947
if err != nil {
946948
return false, err

templates/repo/diff/box.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{{end}}
2525
</div>
2626
<div class="diff-detail-actions">
27-
{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived) (not .DiffNotAvailable)}}
27+
{{if and .PageIsPullFiles $.SignedUserID (not .DiffNotAvailable)}}
2828
<div class="not-mobile tw-flex tw-items-center tw-flex-col tw-whitespace-nowrap tw-mr-1">
2929
<label for="viewed-files-summary" id="viewed-files-summary-label" data-text-changed-template="{{ctx.Locale.Tr "repo.pulls.viewed_files_label"}}">
3030
{{ctx.Locale.Tr "repo.pulls.viewed_files_label" .Diff.NumViewedFiles .Diff.NumFiles}}
@@ -42,7 +42,7 @@
4242
</div>
4343
</div>
4444
{{end}}
45-
{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}}
45+
{{if and .PageIsPullFiles $.SignedUserID}}
4646
{{template "repo/diff/new_review" .}}
4747
{{end}}
4848
</div>
@@ -105,7 +105,7 @@
105105
{{$isCsv := (call $.IsCsvFile $file)}}
106106
{{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}}
107107
{{$isExpandable := or (gt $file.Addition 0) (gt $file.Deletion 0) $file.IsBin}}
108-
{{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.IsArchived) $.IsShowingAllCommits}}
108+
{{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.Repository.IsArchived) $.IsShowingAllCommits}}
109109
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}} tw-mt-0" id="diff-{{$file.NameHash}}" data-old-filename="{{$file.OldName}}" data-new-filename="{{$file.Name}}" {{if or ($file.ShouldBeHidden) (not $isExpandable)}}data-folded="true"{{end}}>
110110
<h4 class="diff-file-header sticky-2nd-row ui top attached header">
111111
<div class="diff-file-name tw-flex tw-flex-1 tw-items-center tw-gap-1 tw-flex-wrap">

templates/repo/diff/comments.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
</div>
4949
{{end}}
5050
{{end}}
51-
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.root.RepoLink .ID)}}
51+
{{if not $.root.Repository.IsArchived}}
52+
{{template "repo/issue/view_content/add_reaction" dict "ActionURL" (printf "%s/comments/%d/reactions" $.root.RepoLink .ID)}}
53+
{{end}}
5254
{{template "repo/issue/view_content/context_menu" dict "item" . "delete" true "issue" false "diff" true "IsCommentPoster" (and $.root.IsSigned (eq $.root.SignedUserID .PosterID))}}
5355
</div>
5456
</div>

templates/repo/diff/new_review.tmpl

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,59 @@
1-
<div id="review-box">
2-
<button class="ui tiny primary button tw-pr-1 tw-flex js-btn-review {{if not $.IsShowingAllCommits}}disabled{{end}}" {{if not $.IsShowingAllCommits}}data-tooltip-content="{{ctx.Locale.Tr "repo.pulls.review_only_possible_for_full_diff"}}"{{end}}>
1+
<div id="review-box" {{if $.Repository.IsArchived}}data-tooltip-content="{{ctx.Locale.Tr "repo.archive.pull.nocomment"}}"{{end}}>
2+
<button class="ui tiny primary button tw-pr-1 js-btn-review {{if not $.IsShowingAllCommits}}disabled{{end}}"
3+
{{if not $.IsShowingAllCommits}}data-tooltip-content="{{ctx.Locale.Tr "repo.pulls.review_only_possible_for_full_diff"}}"{{end}}
4+
{{if $.Repository.IsArchived}}disabled{{end}}
5+
>
36
{{ctx.Locale.Tr "repo.diff.review"}}
47
<span class="ui small label review-comments-counter" data-pending-comment-number="{{.PendingCodeCommentNumber}}">{{.PendingCodeCommentNumber}}</span>
58
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
69
</button>
7-
{{if $.IsShowingAllCommits}}
8-
<div class="review-box-panel tippy-target">
9-
<div class="ui segment">
10-
<form class="ui form form-fetch-action" action="{{.Link}}/reviews/submit" method="post">
11-
{{.CsrfTokenHtml}}
12-
<input type="hidden" name="commit_id" value="{{.AfterCommitID}}">
13-
<div class="field tw-flex tw-items-center">
14-
<div class="tw-flex-1">{{ctx.Locale.Tr "repo.diff.review.header"}}</div>
15-
<a class="muted close">{{svg "octicon-x" 16}}</a>
16-
</div>
10+
</div>
11+
{{if $.IsShowingAllCommits}}
12+
<div class="review-box-panel tippy-target">
13+
<div class="ui segment">
14+
<form class="ui form form-fetch-action" action="{{.Link}}/reviews/submit" method="post">
15+
{{.CsrfTokenHtml}}
16+
<input type="hidden" name="commit_id" value="{{.AfterCommitID}}">
17+
<div class="field tw-flex tw-items-center">
18+
<div class="tw-flex-1">{{ctx.Locale.Tr "repo.diff.review.header"}}</div>
19+
<a class="muted close">{{svg "octicon-x" 16}}</a>
20+
</div>
21+
<div class="field">
22+
{{template "shared/combomarkdowneditor" (dict
23+
"MarkdownPreviewInRepo" $.Repository
24+
"MarkdownPreviewMode" "comment"
25+
"TextareaName" "content"
26+
"TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.review.placeholder")
27+
"DropzoneParentContainer" "form"
28+
)}}
29+
</div>
30+
{{if .IsAttachmentEnabled}}
1731
<div class="field">
18-
{{template "shared/combomarkdowneditor" (dict
19-
"MarkdownPreviewInRepo" $.Repository
20-
"MarkdownPreviewMode" "comment"
21-
"TextareaName" "content"
22-
"TextareaPlaceholder" (ctx.Locale.Tr "repo.diff.review.placeholder")
23-
"DropzoneParentContainer" "form"
24-
)}}
32+
{{template "repo/upload" .}}
2533
</div>
26-
{{if .IsAttachmentEnabled}}
27-
<div class="field">
28-
{{template "repo/upload" .}}
29-
</div>
30-
{{end}}
31-
<div class="divider"></div>
32-
{{$showSelfTooltip := (and $.IsSigned ($.Issue.IsPoster $.SignedUser.ID))}}
33-
{{if not $.Issue.IsClosed}}
34-
{{if $showSelfTooltip}}
35-
<span class="tw-inline-block" data-tooltip-content="{{ctx.Locale.Tr "repo.diff.review.self_approve"}}">
36-
<button type="submit" name="type" value="approve" disabled class="ui submit primary tiny button btn-submit">{{ctx.Locale.Tr "repo.diff.review.approve"}}</button>
37-
</span>
38-
{{else}}
39-
<button type="submit" name="type" value="approve" class="ui submit primary tiny button btn-submit">{{ctx.Locale.Tr "repo.diff.review.approve"}}</button>
40-
{{end}}
34+
{{end}}
35+
<div class="divider"></div>
36+
{{$showSelfTooltip := (and $.IsSigned ($.Issue.IsPoster $.SignedUser.ID))}}
37+
{{if not $.Issue.IsClosed}}
38+
{{if $showSelfTooltip}}
39+
<span class="tw-inline-block" data-tooltip-content="{{ctx.Locale.Tr "repo.diff.review.self_approve"}}">
40+
<button type="submit" name="type" value="approve" disabled class="ui submit primary tiny button btn-submit">{{ctx.Locale.Tr "repo.diff.review.approve"}}</button>
41+
</span>
42+
{{else}}
43+
<button type="submit" name="type" value="approve" class="ui submit primary tiny button btn-submit">{{ctx.Locale.Tr "repo.diff.review.approve"}}</button>
4144
{{end}}
42-
<button type="submit" name="type" value="comment" class="ui submit tiny basic button btn-submit">{{ctx.Locale.Tr "repo.diff.review.comment"}}</button>
43-
{{if not $.Issue.IsClosed}}
44-
{{if $showSelfTooltip}}
45-
<span class="tw-inline-block" data-tooltip-content="{{ctx.Locale.Tr "repo.diff.review.self_reject"}}">
46-
<button type="submit" name="type" value="reject" disabled class="ui submit red tiny button btn-submit">{{ctx.Locale.Tr "repo.diff.review.reject"}}</button>
47-
</span>
48-
{{else}}
49-
<button type="submit" name="type" value="reject" class="ui submit red tiny button btn-submit">{{ctx.Locale.Tr "repo.diff.review.reject"}}</button>
50-
{{end}}
45+
{{end}}
46+
<button type="submit" name="type" value="comment" class="ui submit tiny basic button btn-submit">{{ctx.Locale.Tr "repo.diff.review.comment"}}</button>
47+
{{if not $.Issue.IsClosed}}
48+
{{if $showSelfTooltip}}
49+
<span class="tw-inline-block" data-tooltip-content="{{ctx.Locale.Tr "repo.diff.review.self_reject"}}">
50+
<button type="submit" name="type" value="reject" disabled class="ui submit red tiny button btn-submit">{{ctx.Locale.Tr "repo.diff.review.reject"}}</button>
51+
</span>
52+
{{else}}
53+
<button type="submit" name="type" value="reject" class="ui submit red tiny button btn-submit">{{ctx.Locale.Tr "repo.diff.review.reject"}}</button>
5154
{{end}}
52-
</form>
53-
</div>
55+
{{end}}
56+
</form>
5457
</div>
55-
{{end}}
5658
</div>
59+
{{end}}

web_src/js/features/repo-issue.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,25 +421,19 @@ export function initRepoPullRequestReview() {
421421
// The following part is only for diff views
422422
if (!$('.repository.pull.diff').length) return;
423423

424-
const $reviewBtn = $('.js-btn-review');
425-
const $panel = $reviewBtn.parent().find('.review-box-panel');
426-
const $closeBtn = $panel.find('.close');
427-
428-
if ($reviewBtn.length && $panel.length) {
429-
const tippy = createTippy($reviewBtn[0], {
430-
content: $panel[0],
424+
const elReviewBtn = document.querySelector('.js-btn-review');
425+
const elReviewPanel = document.querySelector('.review-box-panel.tippy-target');
426+
if (elReviewBtn && elReviewPanel) {
427+
const tippy = createTippy(elReviewBtn, {
428+
content: elReviewPanel,
431429
theme: 'default',
432430
placement: 'bottom',
433431
trigger: 'click',
434432
maxWidth: 'none',
435433
interactive: true,
436434
hideOnClick: true,
437435
});
438-
439-
$closeBtn.on('click', (e) => {
440-
e.preventDefault();
441-
tippy.hide();
442-
});
436+
elReviewPanel.querySelector('.close').addEventListener('click', () => tippy.hide());
443437
}
444438

445439
addDelegatedEventListener(document, 'click', '.add-code-comment', async (el, e) => {

0 commit comments

Comments
 (0)