mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-19 17:43:58 +09:00
Backport https://github.com/go-gitea/gitea/pull/39839 by @silverwind Several handlers and model helpers skipped checks that their siblings already perform. - Only match principal keys when looking up SSH certificate principals - Return no attachments for an unsaved issue instead of every issue-less one - Reject issue and comment attachments when adding release attachments - Share one permission check for editing, deleting and reacting to issue content and for comment attachments between the web UI and the API, refusing them on locked issues for users who can't write - Reject issue edits, deletion and label changes in archived repositories via the API - Apply cross-origin protection to the repository topics endpoint - Return 404 for the repositories tab of individual users and respect profile visibility for the heatmap * Fixes: https://github.com/go-gitea/gitea/issues/39226 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: bircni <bircni@icloud.com>
32 lines
1.4 KiB
TypeScript
32 lines
1.4 KiB
TypeScript
import {POST} from '../../modules/fetch.ts';
|
|
import {registerGlobalEventFunc} from '../../modules/observer.ts';
|
|
|
|
export function initCompReactionSelector() {
|
|
registerGlobalEventFunc('click', 'onCommentReactionButtonClick', async (target: HTMLElement, e: Event) => {
|
|
// there are 2 places for the "reaction" buttons, one is the top-right reaction menu, one is the bottom of the comment
|
|
e.preventDefault();
|
|
|
|
if (target.classList.contains('disabled')) return;
|
|
|
|
const actionUrl = target.closest('[data-action-url]')!.getAttribute('data-action-url');
|
|
const reactionContent = target.getAttribute('data-reaction-content')!;
|
|
|
|
const commentContainer = target.closest('.comment-container')!;
|
|
|
|
const bottomReactions = commentContainer.querySelector('.bottom-reactions'); // may not exist if there is no reaction
|
|
const bottomReactionBtn = bottomReactions?.querySelector(`a[data-reaction-content="${CSS.escape(reactionContent)}"]`);
|
|
const hasReacted = bottomReactionBtn?.getAttribute('data-has-reacted') === 'true';
|
|
|
|
const res = await POST(`${actionUrl}/${hasReacted ? 'unreact' : 'react'}`, {
|
|
data: new URLSearchParams({content: reactionContent}),
|
|
});
|
|
if (!res.ok) return;
|
|
|
|
const data = await res.json();
|
|
bottomReactions?.remove();
|
|
if (data.html) {
|
|
commentContainer.insertAdjacentHTML('beforeend', data.html);
|
|
}
|
|
});
|
|
}
|