feat(board): redesign classifieds + Slack channel creation
Adds AdminGhost bot token for admin-only Slack channel creation, refreshes BoardPostCard/Form layouts, and expands admin board-channels management.
This commit is contained in:
parent
6f3d088763
commit
9a560f2a3b
14 changed files with 544 additions and 158 deletions
|
|
@ -14,6 +14,8 @@ RESEND_FROM_EMAIL=noreply@ghostguild.org
|
||||||
# Slack Integration
|
# Slack Integration
|
||||||
SLACK_WEBHOOK_URL=your-slack-webhook-url
|
SLACK_WEBHOOK_URL=your-slack-webhook-url
|
||||||
SLACK_OAUTH_TOKEN=your-slack-oauth-token
|
SLACK_OAUTH_TOKEN=your-slack-oauth-token
|
||||||
|
# AdminGhost bot token — used for admin-only channel creation. Falls back to SLACK_BOT_TOKEN if unset.
|
||||||
|
SLACK_ADMIN_BOT_TOKEN=xoxb-adminghost-token
|
||||||
|
|
||||||
# JWT Secret for authentication
|
# JWT Secret for authentication
|
||||||
JWT_SECRET=your-jwt-secret-key-change-this-in-production
|
JWT_SECRET=your-jwt-secret-key-change-this-in-production
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<article class="board-post">
|
<article class="board-post">
|
||||||
<header class="post-header">
|
<header class="post-header">
|
||||||
<span class="type-indicator" :class="typeClass">{{ typeLabel }}</span>
|
<span class="post-meta">{{ typeLabel }}</span>
|
||||||
<div v-if="editable" class="post-actions">
|
<div v-if="editable" class="post-actions">
|
||||||
<button type="button" class="action-btn" @click="$emit('edit', post)">Edit</button>
|
<button type="button" class="action-btn" @click="$emit('edit', post)">Edit</button>
|
||||||
<button type="button" class="action-btn danger" @click="$emit('delete', post)">Delete</button>
|
<button type="button" class="action-btn danger" @click="$emit('delete', post)">Delete</button>
|
||||||
|
|
@ -23,31 +23,49 @@
|
||||||
<p v-if="post.note" class="post-note">{{ post.note }}</p>
|
<p v-if="post.note" class="post-note">{{ post.note }}</p>
|
||||||
|
|
||||||
<div v-if="post.tags && post.tags.length" class="post-tags">
|
<div v-if="post.tags && post.tags.length" class="post-tags">
|
||||||
<span v-for="tag in post.tags" :key="tag" class="tag-pill">{{ tag }}</span>
|
<span v-for="slug in post.tags" :key="slug" class="tag-pill">{{ tagLabel(slug) }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<footer class="post-footer">
|
<footer class="post-footer">
|
||||||
<div class="author">
|
<div class="author">
|
||||||
<img
|
<img
|
||||||
v-if="post.author && post.author.avatar"
|
v-if="authorAvatar"
|
||||||
:src="post.author.avatar"
|
:src="authorAvatar"
|
||||||
:alt="post.author.name"
|
:alt="post.author.name"
|
||||||
class="author-avatar"
|
class="author-avatar"
|
||||||
>
|
>
|
||||||
<span v-else class="author-avatar avatar-placeholder" />
|
<span v-else class="author-avatar avatar-placeholder" />
|
||||||
<span class="author-name">{{ post.author ? post.author.name : 'Unknown' }}</span>
|
<span class="author-name">{{ post.author ? post.author.name : 'Unknown' }}</span>
|
||||||
<CircleBadge
|
<span v-if="slackHandle" class="slack-handle-wrap">
|
||||||
v-if="post.author && post.author.circle"
|
<button
|
||||||
:circle="post.author.circle"
|
type="button"
|
||||||
/>
|
class="slack-handle"
|
||||||
|
:title="copied ? 'Copied!' : 'Click to copy Slack handle'"
|
||||||
|
@click="copySlackHandle"
|
||||||
|
>@{{ slackHandle }}</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="copy-link"
|
||||||
|
:class="{ copied }"
|
||||||
|
@click="copySlackHandle"
|
||||||
|
>{{ copied ? 'Copied!' : 'Copy' }}</button>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<a
|
<a
|
||||||
v-if="slackLink"
|
v-if="slackLinks.length === 1"
|
||||||
:href="slackLink"
|
:href="slackLinks[0].url"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener"
|
rel="noopener"
|
||||||
class="slack-link"
|
class="slack-link"
|
||||||
>Discuss on Slack →</a>
|
>Discuss in #{{ slackLinks[0].name }} →</a>
|
||||||
|
<details v-else-if="slackLinks.length > 1" class="slack-menu">
|
||||||
|
<summary class="slack-link">Discuss on Slack ▾</summary>
|
||||||
|
<ul class="slack-menu-list">
|
||||||
|
<li v-for="link in slackLinks" :key="link.id">
|
||||||
|
<a :href="link.url" target="_blank" rel="noopener" class="slack-link">#{{ link.name }}</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</details>
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -56,11 +74,47 @@
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
post: { type: Object, required: true },
|
post: { type: Object, required: true },
|
||||||
channels: { type: Array, default: () => [] },
|
channels: { type: Array, default: () => [] },
|
||||||
|
tags: { type: Array, default: () => [] },
|
||||||
editable: { type: Boolean, default: false },
|
editable: { type: Boolean, default: false },
|
||||||
})
|
})
|
||||||
|
|
||||||
defineEmits(['edit', 'delete'])
|
defineEmits(['edit', 'delete'])
|
||||||
|
|
||||||
|
const capitalizeAvatar = (str) => {
|
||||||
|
if (str.toLowerCase() === 'wtf') return 'WTF'
|
||||||
|
return str
|
||||||
|
.split('-')
|
||||||
|
.map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
|
||||||
|
.join('-')
|
||||||
|
}
|
||||||
|
|
||||||
|
const authorAvatar = computed(() => {
|
||||||
|
const a = props.post.author?.avatar
|
||||||
|
if (!a) return null
|
||||||
|
return `/ghosties/Ghost-${capitalizeAvatar(a)}.png`
|
||||||
|
})
|
||||||
|
|
||||||
|
const slackHandle = computed(() => props.post.author?.board?.slackHandle || '')
|
||||||
|
|
||||||
|
const copied = ref(false)
|
||||||
|
const copySlackHandle = async () => {
|
||||||
|
if (!slackHandle.value) return
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(`@${slackHandle.value}`)
|
||||||
|
copied.value = true
|
||||||
|
setTimeout(() => { copied.value = false }, 1500)
|
||||||
|
} catch {
|
||||||
|
// clipboard unavailable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tagLabelMap = computed(() => {
|
||||||
|
const map = {}
|
||||||
|
for (const t of props.tags) map[t.slug] = t.label || t.name || t.slug
|
||||||
|
return map
|
||||||
|
})
|
||||||
|
const tagLabel = (slug) => tagLabelMap.value[slug] || slug
|
||||||
|
|
||||||
const hasSeeking = computed(() => !!(props.post.seeking && props.post.seeking.trim()))
|
const hasSeeking = computed(() => !!(props.post.seeking && props.post.seeking.trim()))
|
||||||
const hasOffering = computed(() => !!(props.post.offering && props.post.offering.trim()))
|
const hasOffering = computed(() => !!(props.post.offering && props.post.offering.trim()))
|
||||||
|
|
||||||
|
|
@ -71,22 +125,20 @@ const typeLabel = computed(() => {
|
||||||
return ''
|
return ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const typeClass = computed(() => {
|
const slackLinks = computed(() => {
|
||||||
if (hasSeeking.value && hasOffering.value) return 'type-both'
|
|
||||||
if (hasSeeking.value) return 'type-seeking'
|
|
||||||
if (hasOffering.value) return 'type-offering'
|
|
||||||
return ''
|
|
||||||
})
|
|
||||||
|
|
||||||
const slackLink = computed(() => {
|
|
||||||
const postTags = props.post.tags || []
|
const postTags = props.post.tags || []
|
||||||
if (!postTags.length) return null
|
if (!postTags.length) return []
|
||||||
const channel = props.channels.find(c => {
|
return props.channels
|
||||||
const slugs = c.tagSlugs || []
|
.filter((c) => {
|
||||||
return slugs.some(s => postTags.includes(s))
|
if (!c.slackChannelId) return false
|
||||||
})
|
const slugs = c.tagSlugs || []
|
||||||
if (!channel || !channel.slackChannelId) return null
|
return slugs.some((s) => postTags.includes(s))
|
||||||
return `https://gammaspace.slack.com/archives/${channel.slackChannelId}`
|
})
|
||||||
|
.map((c) => ({
|
||||||
|
id: c.slackChannelId,
|
||||||
|
name: c.slackChannelName || c.name || c.slackChannelId,
|
||||||
|
url: `https://gammaspace.slack.com/archives/${c.slackChannelId}`,
|
||||||
|
}))
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -94,41 +146,26 @@ const slackLink = computed(() => {
|
||||||
.board-post {
|
.board-post {
|
||||||
border: 1px dashed var(--border);
|
border: 1px dashed var(--border);
|
||||||
padding: 18px 22px;
|
padding: 18px 22px;
|
||||||
transition: background 0.15s, border-color 0.15s;
|
|
||||||
}
|
|
||||||
.board-post:hover {
|
|
||||||
background: var(--surface);
|
background: var(--surface);
|
||||||
border-color: var(--border-d);
|
break-inside: avoid;
|
||||||
|
-webkit-column-break-inside: avoid;
|
||||||
|
page-break-inside: avoid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-header {
|
.post-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: baseline;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.type-indicator {
|
.post-meta {
|
||||||
display: inline-block;
|
|
||||||
font-size: 10px;
|
|
||||||
letter-spacing: 0.08em;
|
|
||||||
text-transform: uppercase;
|
|
||||||
padding: 2px 8px;
|
|
||||||
border: 1px dashed;
|
|
||||||
font-family: "Commit Mono", monospace;
|
font-family: "Commit Mono", monospace;
|
||||||
}
|
font-size: 10px;
|
||||||
.type-indicator.type-seeking {
|
letter-spacing: 0.1em;
|
||||||
color: var(--candle);
|
text-transform: uppercase;
|
||||||
border-color: var(--candle-faint);
|
color: var(--text-faint);
|
||||||
}
|
|
||||||
.type-indicator.type-offering {
|
|
||||||
color: var(--green);
|
|
||||||
border-color: var(--green);
|
|
||||||
}
|
|
||||||
.type-indicator.type-both {
|
|
||||||
color: var(--ember);
|
|
||||||
border-color: var(--ember);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-actions {
|
.post-actions {
|
||||||
|
|
@ -157,11 +194,11 @@ const slackLink = computed(() => {
|
||||||
|
|
||||||
.post-title {
|
.post-title {
|
||||||
font-family: "Brygada 1918", serif;
|
font-family: "Brygada 1918", serif;
|
||||||
font-size: 20px;
|
font-size: 19px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: var(--text-bright);
|
color: var(--text-bright);
|
||||||
margin-bottom: 10px;
|
margin: 0 0 12px;
|
||||||
line-height: 1.25;
|
line-height: 1.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-block {
|
.post-block {
|
||||||
|
|
@ -205,9 +242,9 @@ const slackLink = computed(() => {
|
||||||
|
|
||||||
.post-footer {
|
.post-footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: flex-start;
|
||||||
gap: 12px;
|
gap: 8px;
|
||||||
margin-top: 14px;
|
margin-top: 14px;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
border-top: 1px dashed var(--border);
|
border-top: 1px dashed var(--border);
|
||||||
|
|
@ -216,13 +253,13 @@ const slackLink = computed(() => {
|
||||||
.author {
|
.author {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
flex-wrap: wrap;
|
||||||
|
gap: 6px 8px;
|
||||||
}
|
}
|
||||||
.author-avatar {
|
.author-avatar {
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
border: 1px dashed var(--border);
|
|
||||||
}
|
}
|
||||||
.avatar-placeholder {
|
.avatar-placeholder {
|
||||||
background: var(--surface);
|
background: var(--surface);
|
||||||
|
|
@ -232,7 +269,66 @@ const slackLink = computed(() => {
|
||||||
color: var(--text-dim);
|
color: var(--text-dim);
|
||||||
font-family: "Commit Mono", monospace;
|
font-family: "Commit Mono", monospace;
|
||||||
}
|
}
|
||||||
|
.slack-handle-wrap {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.slack-handle {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-faint);
|
||||||
|
font-family: "Commit Mono", monospace;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.slack-handle:hover {
|
||||||
|
color: var(--candle);
|
||||||
|
}
|
||||||
|
.copy-link {
|
||||||
|
font-size: 11px;
|
||||||
|
font-family: "Commit Mono", monospace;
|
||||||
|
color: var(--candle);
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
.copy-link:hover {
|
||||||
|
color: var(--candle-dim);
|
||||||
|
}
|
||||||
|
.copy-link.copied {
|
||||||
|
color: var(--candle);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slack-menu {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.slack-menu > summary {
|
||||||
|
list-style: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.slack-menu > summary::-webkit-details-marker {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.slack-menu-list {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 100%;
|
||||||
|
margin-top: 6px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
list-style: none;
|
||||||
|
background: var(--surface);
|
||||||
|
border: 1px dashed var(--border);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
white-space: nowrap;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
.slack-link {
|
.slack-link {
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
font-family: "Commit Mono", monospace;
|
font-family: "Commit Mono", monospace;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<form class="post-form" @submit.prevent="handleSubmit">
|
<form class="post-form" @submit.prevent="handleSubmit">
|
||||||
<div class="form-header">
|
<div class="form-header">
|
||||||
<h3 class="form-title">{{ isEdit ? 'Edit post' : 'New post' }}</h3>
|
<h3 class="form-title">{{ isEdit ? 'Edit post' : 'New post' }}</h3>
|
||||||
|
<p class="form-hint">Fill in <em>Seeking</em> or <em>Offering</em> (or both).</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|
@ -13,35 +14,34 @@
|
||||||
maxlength="120"
|
maxlength="120"
|
||||||
placeholder="Short summary"
|
placeholder="Short summary"
|
||||||
>
|
>
|
||||||
<div class="char-count">{{ form.title.length }}/120</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="field-row">
|
||||||
|
<div class="field">
|
||||||
|
<label for="post-seeking">Seeking <span class="opt">(optional)</span></label>
|
||||||
|
<textarea
|
||||||
|
id="post-seeking"
|
||||||
|
v-model="form.seeking"
|
||||||
|
rows="2"
|
||||||
|
maxlength="500"
|
||||||
|
placeholder="What are you looking for?"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label for="post-offering">Offering <span class="opt">(optional)</span></label>
|
||||||
|
<textarea
|
||||||
|
id="post-offering"
|
||||||
|
v-model="form.offering"
|
||||||
|
rows="2"
|
||||||
|
maxlength="500"
|
||||||
|
placeholder="What can you offer?"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="post-seeking">Seeking</label>
|
<label for="post-note">Note <span class="opt">(optional)</span></label>
|
||||||
<textarea
|
|
||||||
id="post-seeking"
|
|
||||||
v-model="form.seeking"
|
|
||||||
rows="3"
|
|
||||||
maxlength="500"
|
|
||||||
placeholder="What are you looking for?"
|
|
||||||
/>
|
|
||||||
<div class="char-count">{{ form.seeking.length }}/500</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field">
|
|
||||||
<label for="post-offering">Offering</label>
|
|
||||||
<textarea
|
|
||||||
id="post-offering"
|
|
||||||
v-model="form.offering"
|
|
||||||
rows="3"
|
|
||||||
maxlength="500"
|
|
||||||
placeholder="What can you offer?"
|
|
||||||
/>
|
|
||||||
<div class="char-count">{{ form.offering.length }}/500</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field">
|
|
||||||
<label for="post-note">Note (optional)</label>
|
|
||||||
<textarea
|
<textarea
|
||||||
id="post-note"
|
id="post-note"
|
||||||
v-model="form.note"
|
v-model="form.note"
|
||||||
|
|
@ -49,7 +49,6 @@
|
||||||
maxlength="300"
|
maxlength="300"
|
||||||
placeholder="Anything else to add?"
|
placeholder="Anything else to add?"
|
||||||
/>
|
/>
|
||||||
<div class="char-count">{{ form.note.length }}/300</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="tags.length" class="field">
|
<div v-if="tags.length" class="field">
|
||||||
|
|
@ -139,22 +138,38 @@ function handleSubmit() {
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.post-form {
|
.post-form {
|
||||||
border: 1px dashed var(--border);
|
border: 1px dashed var(--border);
|
||||||
padding: 20px 24px;
|
padding: 14px 16px;
|
||||||
background: var(--bg);
|
background: var(--bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-header {
|
.form-header {
|
||||||
margin-bottom: 14px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
.form-title {
|
.form-title {
|
||||||
font-family: "Brygada 1918", serif;
|
font-family: "Brygada 1918", serif;
|
||||||
font-size: 18px;
|
font-size: 15px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: var(--text-bright);
|
color: var(--text-bright);
|
||||||
}
|
}
|
||||||
|
.form-hint {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-faint);
|
||||||
|
font-family: "Commit Mono", monospace;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
.form-hint em {
|
||||||
|
color: var(--text-dim);
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
.field {
|
.field {
|
||||||
margin-bottom: 12px;
|
margin-bottom: 8px;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.field-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
}
|
}
|
||||||
.field label {
|
.field label {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
@ -164,12 +179,20 @@ function handleSubmit() {
|
||||||
color: var(--text-faint);
|
color: var(--text-faint);
|
||||||
margin-bottom: 3px;
|
margin-bottom: 3px;
|
||||||
}
|
}
|
||||||
|
.field label .opt {
|
||||||
|
color: var(--text-faint);
|
||||||
|
text-transform: none;
|
||||||
|
letter-spacing: 0;
|
||||||
|
font-size: 9px;
|
||||||
|
margin-left: 4px;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
.field input,
|
.field input,
|
||||||
.field textarea {
|
.field textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 5px 8px;
|
padding: 4px 8px;
|
||||||
font-family: "Commit Mono", monospace;
|
font-family: "Commit Mono", monospace;
|
||||||
font-size: 13px;
|
font-size: 12px;
|
||||||
color: var(--text-bright);
|
color: var(--text-bright);
|
||||||
background: var(--input-bg);
|
background: var(--input-bg);
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
|
|
@ -232,8 +255,15 @@ function handleSubmit() {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
margin-top: 14px;
|
margin-top: 10px;
|
||||||
padding-top: 12px;
|
padding-top: 8px;
|
||||||
border-top: 1px dashed var(--border);
|
border-top: 1px dashed var(--border);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.field-row {
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<div class="header-row">
|
<div class="header-row">
|
||||||
<div>
|
<div>
|
||||||
<h1>Board Channels</h1>
|
<h1>Board Channels</h1>
|
||||||
<p>Map cooperative tags to Slack channels for board cross-posting</p>
|
<p>Create Slack channels for cooperative tags. New channels are created in Slack when you click Create Channel.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="header-actions">
|
<div class="header-actions">
|
||||||
<button class="btn btn-primary" @click="openCreateModal">+ New Channel</button>
|
<button class="btn btn-primary" @click="openCreateModal">+ New Channel</button>
|
||||||
|
|
@ -28,22 +28,23 @@
|
||||||
<div class="channels-list">
|
<div class="channels-list">
|
||||||
<div v-if="!channels.length" class="empty-state">
|
<div v-if="!channels.length" class="empty-state">
|
||||||
<p>No board channels configured yet.</p>
|
<p>No board channels configured yet.</p>
|
||||||
<p class="empty-hint">Click "+ New Channel" to map your first tag to a Slack channel.</p>
|
<p class="empty-hint">Click "+ New Channel" to create your first board channel in Slack.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table v-else class="channels-table">
|
<table v-else class="channels-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Channel</th>
|
||||||
<th>Slack Channel ID</th>
|
|
||||||
<th>Mapped Tags</th>
|
<th>Mapped Tags</th>
|
||||||
<th class="actions-col">Actions</th>
|
<th class="actions-col">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="channel in channels" :key="channel._id">
|
<tr v-for="channel in channels" :key="channel._id">
|
||||||
<td class="name-cell">{{ channel.name }}</td>
|
<td class="name-cell">
|
||||||
<td class="mono">{{ channel.slackChannelId }}</td>
|
<div class="channel-name">{{ channel.name }}</div>
|
||||||
|
<div class="channel-id">{{ channel.slackChannelId }}</div>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="tag-pills">
|
<div class="tag-pills">
|
||||||
<span
|
<span
|
||||||
|
|
@ -75,32 +76,39 @@
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Name</label>
|
<label>Name</label>
|
||||||
<input v-model="formData.name" type="text" placeholder="e.g., #coop-formation" />
|
<input v-model="formData.name" type="text" placeholder="e.g., coop-formation" />
|
||||||
|
<p v-if="!editingId" class="help-text">A new Slack channel will be created with this name. Lowercase, letters/numbers/dashes only.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div v-if="editingId" class="field">
|
||||||
<label>Slack Channel ID</label>
|
<label>Slack Channel ID</label>
|
||||||
<input v-model="formData.slackChannelId" type="text" placeholder="C0123456789" />
|
<input v-model="formData.slackChannelId" type="text" placeholder="C0123456789" />
|
||||||
<p class="help-text">The Slack channel ID (starts with C). Find it in channel settings.</p>
|
<p class="help-text">The Slack channel ID (starts with C).</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Mapped Tags</label>
|
<label>Mapped Tags</label>
|
||||||
<p class="help-text">Cooperative tags that route posts to this channel.</p>
|
<p class="help-text">Cooperative tags that route posts to this channel.</p>
|
||||||
<div class="tag-select">
|
<div class="pill-grid">
|
||||||
<label
|
<button
|
||||||
v-for="tag in cooperativeTags"
|
v-for="tag in cooperativeTags"
|
||||||
:key="tag.slug"
|
:key="tag.slug"
|
||||||
class="tag-checkbox"
|
type="button"
|
||||||
>
|
class="pill"
|
||||||
<input
|
:class="{
|
||||||
type="checkbox"
|
selected: formData.tagSlugs.includes(tag.slug),
|
||||||
:value="tag.slug"
|
disabled: tagOwner(tag.slug) && !formData.tagSlugs.includes(tag.slug),
|
||||||
:checked="formData.tagSlugs.includes(tag.slug)"
|
}"
|
||||||
@change="toggleTag(tag.slug)"
|
:disabled="!!(tagOwner(tag.slug) && !formData.tagSlugs.includes(tag.slug))"
|
||||||
/>
|
:title="tagOwner(tag.slug) && !formData.tagSlugs.includes(tag.slug)
|
||||||
<span>{{ tag.label }}</span>
|
? `Already mapped to ${tagOwner(tag.slug)}`
|
||||||
</label>
|
: ''"
|
||||||
|
@click="toggleTag(tag.slug)"
|
||||||
|
>{{ tag.label }}<span
|
||||||
|
v-if="tagOwner(tag.slug) && !formData.tagSlugs.includes(tag.slug)"
|
||||||
|
class="pill-owner"
|
||||||
|
> · {{ tagOwner(tag.slug) }}</span></button>
|
||||||
<p v-if="!cooperativeTags.length" class="help-text">No cooperative tags available.</p>
|
<p v-if="!cooperativeTags.length" class="help-text">No cooperative tags available.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<p class="help-text">Each tag can only be mapped to one channel.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-actions">
|
<div class="modal-actions">
|
||||||
|
|
@ -148,6 +156,18 @@ const mappedSlugs = computed(() => {
|
||||||
return set
|
return set
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Map of slug -> channel name, EXCLUDING the channel currently being edited.
|
||||||
|
const otherChannelTagMap = computed(() => {
|
||||||
|
const map = {}
|
||||||
|
for (const ch of channels.value) {
|
||||||
|
if (editingId.value && String(ch._id) === String(editingId.value)) continue
|
||||||
|
for (const slug of ch.tagSlugs || []) map[slug] = ch.name
|
||||||
|
}
|
||||||
|
return map
|
||||||
|
})
|
||||||
|
|
||||||
|
const tagOwner = (slug) => otherChannelTagMap.value[slug] || ''
|
||||||
|
|
||||||
const unmappedTags = computed(() =>
|
const unmappedTags = computed(() =>
|
||||||
cooperativeTags.value.filter((t) => !mappedSlugs.value.has(t.slug)),
|
cooperativeTags.value.filter((t) => !mappedSlugs.value.has(t.slug)),
|
||||||
)
|
)
|
||||||
|
|
@ -195,10 +215,18 @@ const toggleTag = (slug) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveChannel = async () => {
|
const saveChannel = async () => {
|
||||||
if (!formData.name.trim() || !formData.slackChannelId.trim()) {
|
if (!formData.name.trim()) {
|
||||||
toast.add({
|
toast.add({
|
||||||
title: 'Missing fields',
|
title: 'Missing fields',
|
||||||
description: 'Name and Slack channel ID are required.',
|
description: 'Name is required.',
|
||||||
|
color: 'red',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (editingId.value && !formData.slackChannelId.trim()) {
|
||||||
|
toast.add({
|
||||||
|
title: 'Missing fields',
|
||||||
|
description: 'Slack channel ID is required.',
|
||||||
color: 'red',
|
color: 'red',
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|
@ -208,9 +236,11 @@ const saveChannel = async () => {
|
||||||
try {
|
try {
|
||||||
const body = {
|
const body = {
|
||||||
name: formData.name.trim(),
|
name: formData.name.trim(),
|
||||||
slackChannelId: formData.slackChannelId.trim(),
|
|
||||||
tagSlugs: formData.tagSlugs,
|
tagSlugs: formData.tagSlugs,
|
||||||
}
|
}
|
||||||
|
if (formData.slackChannelId.trim()) {
|
||||||
|
body.slackChannelId = formData.slackChannelId.trim()
|
||||||
|
}
|
||||||
if (editingId.value) {
|
if (editingId.value) {
|
||||||
await $fetch(`/api/admin/board-channels/${editingId.value}`, {
|
await $fetch(`/api/admin/board-channels/${editingId.value}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
|
|
@ -323,11 +353,12 @@ onMounted(() => {
|
||||||
|
|
||||||
.tag-pill {
|
.tag-pill {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 2px 8px;
|
padding: 2px 9px;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
background: var(--bg);
|
font-family: "Commit Mono", monospace;
|
||||||
border: 1px solid var(--border);
|
background: transparent;
|
||||||
color: var(--text);
|
border: 1px dashed var(--border);
|
||||||
|
color: var(--text-dim);
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag-pill-warning {
|
.tag-pill-warning {
|
||||||
|
|
@ -373,14 +404,14 @@ onMounted(() => {
|
||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.name-cell {
|
.channel-name {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
.channel-id {
|
||||||
.mono {
|
|
||||||
font-family: 'Commit Mono', monospace;
|
font-family: 'Commit Mono', monospace;
|
||||||
font-size: 12px;
|
font-size: 11px;
|
||||||
color: var(--text-dim);
|
color: var(--text-faint);
|
||||||
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.actions-col {
|
.actions-col {
|
||||||
|
|
@ -517,24 +548,49 @@ onMounted(() => {
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag-select {
|
.pill-grid {
|
||||||
border: 1px dashed var(--border);
|
|
||||||
padding: 10px;
|
|
||||||
max-height: 200px;
|
|
||||||
overflow-y: auto;
|
|
||||||
background: var(--input-bg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-checkbox {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
flex-wrap: wrap;
|
||||||
gap: 8px;
|
gap: 4px;
|
||||||
padding: 4px 0;
|
max-height: 240px;
|
||||||
font-size: 13px;
|
overflow-y: auto;
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
.pill {
|
||||||
.tag-checkbox input {
|
display: inline-flex;
|
||||||
margin: 0;
|
align-items: center;
|
||||||
|
padding: 2px 9px;
|
||||||
|
border: 1px dashed var(--border);
|
||||||
|
background: transparent;
|
||||||
|
color: var(--text-faint);
|
||||||
|
font-size: 11px;
|
||||||
|
font-family: "Commit Mono", monospace;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
transition: all 0.12s;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.pill:hover {
|
||||||
|
color: var(--text-dim);
|
||||||
|
border-color: var(--border-d);
|
||||||
|
}
|
||||||
|
.pill.selected {
|
||||||
|
background: var(--surface);
|
||||||
|
color: var(--text-bright);
|
||||||
|
border-color: var(--candle);
|
||||||
|
border-style: solid;
|
||||||
|
}
|
||||||
|
.pill.disabled,
|
||||||
|
.pill:disabled {
|
||||||
|
opacity: 0.45;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
.pill.disabled:hover {
|
||||||
|
color: var(--text-faint);
|
||||||
|
border-color: var(--border);
|
||||||
|
}
|
||||||
|
.pill-owner {
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--text-faint);
|
||||||
|
margin-left: 2px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<PageShell title="Board" :subtitle="pageSubtitle">
|
<PageShell title="Bulletin Board" :subtitle="pageSubtitle">
|
||||||
<!-- Action bar -->
|
<!-- Action bar -->
|
||||||
<div class="action-bar">
|
<div class="action-bar">
|
||||||
<button type="button" class="new-post-btn" @click="openNewForm">
|
<button type="button" class="new-post-btn" @click="openNewForm">
|
||||||
|
|
@ -71,6 +71,7 @@
|
||||||
:key="post._id"
|
:key="post._id"
|
||||||
:post="post"
|
:post="post"
|
||||||
:channels="channels"
|
:channels="channels"
|
||||||
|
:tags="cooperativeTags"
|
||||||
:editable="isAuthor(post)"
|
:editable="isAuthor(post)"
|
||||||
@edit="handleEdit"
|
@edit="handleEdit"
|
||||||
@delete="handleDelete"
|
@delete="handleDelete"
|
||||||
|
|
@ -302,17 +303,27 @@ onMounted(async () => {
|
||||||
|
|
||||||
/* ---- FORM WRAPPER ---- */
|
/* ---- FORM WRAPPER ---- */
|
||||||
.form-wrapper {
|
.form-wrapper {
|
||||||
padding: 20px 24px;
|
padding: 16px 24px;
|
||||||
border-bottom: 1px dashed var(--border);
|
border-bottom: 1px dashed var(--border);
|
||||||
|
max-width: 640px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---- POST GRID ---- */
|
/* ---- POST GRID (masonry via CSS columns) ---- */
|
||||||
.post-grid {
|
.post-grid {
|
||||||
display: grid;
|
column-count: 2;
|
||||||
grid-template-columns: repeat(2, 1fr);
|
column-gap: 16px;
|
||||||
gap: 16px;
|
|
||||||
padding: 20px 24px;
|
padding: 20px 24px;
|
||||||
}
|
}
|
||||||
|
.post-grid > * {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0 0 16px;
|
||||||
|
}
|
||||||
|
@media (min-width: 1400px) {
|
||||||
|
.post-grid {
|
||||||
|
column-count: 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ---- LOADING / EMPTY ---- */
|
/* ---- LOADING / EMPTY ---- */
|
||||||
.loading-state {
|
.loading-state {
|
||||||
|
|
@ -340,7 +351,7 @@ onMounted(async () => {
|
||||||
/* ---- RESPONSIVE ---- */
|
/* ---- RESPONSIVE ---- */
|
||||||
@media (max-width: 1024px) {
|
@media (max-width: 1024px) {
|
||||||
.post-grid {
|
.post-grid {
|
||||||
grid-template-columns: 1fr;
|
column-count: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
|
|
|
||||||
|
|
@ -528,7 +528,6 @@ useHead({
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
border: 1px dashed var(--border);
|
|
||||||
background: var(--bg);
|
background: var(--bg);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,6 @@ useHead({
|
||||||
width: 96px;
|
width: 96px;
|
||||||
height: 96px;
|
height: 96px;
|
||||||
background: var(--surface);
|
background: var(--surface);
|
||||||
border: 1px dashed var(--border);
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
|
||||||
|
|
@ -580,7 +580,6 @@ onMounted(async () => {
|
||||||
width: 32px;
|
width: 32px;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
background: var(--surface);
|
background: var(--surface);
|
||||||
border: 1px dashed var(--border);
|
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ export default defineNuxtConfig({
|
||||||
resendApiKey: process.env.RESEND_API_KEY || "",
|
resendApiKey: process.env.RESEND_API_KEY || "",
|
||||||
helcimApiToken: process.env.HELCIM_API_TOKEN || "", // also exposed to client via public.helcimToken
|
helcimApiToken: process.env.HELCIM_API_TOKEN || "", // also exposed to client via public.helcimToken
|
||||||
slackBotToken: process.env.SLACK_BOT_TOKEN || "",
|
slackBotToken: process.env.SLACK_BOT_TOKEN || "",
|
||||||
|
slackAdminBotToken: process.env.SLACK_ADMIN_BOT_TOKEN || "",
|
||||||
slackSigningSecret: process.env.SLACK_SIGNING_SECRET || "",
|
slackSigningSecret: process.env.SLACK_SIGNING_SECRET || "",
|
||||||
slackVettingChannelId: process.env.SLACK_VETTING_CHANNEL_ID || "",
|
slackVettingChannelId: process.env.SLACK_VETTING_CHANNEL_ID || "",
|
||||||
oidcClientId: process.env.OIDC_CLIENT_ID || "outline-wiki",
|
oidcClientId: process.env.OIDC_CLIENT_ID || "outline-wiki",
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,51 @@ import BoardChannel from '../../models/boardChannel.js'
|
||||||
import { requireAdmin } from '../../utils/auth.js'
|
import { requireAdmin } from '../../utils/auth.js'
|
||||||
import { validateBody } from '../../utils/validateBody.js'
|
import { validateBody } from '../../utils/validateBody.js'
|
||||||
import { boardChannelCreateSchema } from '../../utils/schemas.js'
|
import { boardChannelCreateSchema } from '../../utils/schemas.js'
|
||||||
|
import { getSlackAdminService } from '../../utils/slack.ts'
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
await requireAdmin(event)
|
await requireAdmin(event)
|
||||||
|
|
||||||
const body = await validateBody(event, boardChannelCreateSchema)
|
const body = await validateBody(event, boardChannelCreateSchema)
|
||||||
|
|
||||||
|
if (body.tagSlugs && body.tagSlugs.length) {
|
||||||
|
const conflict = await BoardChannel.findOne({ tagSlugs: { $in: body.tagSlugs } }).lean()
|
||||||
|
if (conflict) {
|
||||||
|
const taken = (conflict.tagSlugs || []).filter((s) => body.tagSlugs.includes(s))
|
||||||
|
throw createError({
|
||||||
|
statusCode: 409,
|
||||||
|
statusMessage: `Tag${taken.length > 1 ? 's' : ''} already mapped to "${conflict.name}": ${taken.join(', ')}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let slackChannelId = body.slackChannelId
|
||||||
|
let channelName = body.name
|
||||||
|
|
||||||
|
if (!slackChannelId) {
|
||||||
|
const slack = getSlackAdminService()
|
||||||
|
if (!slack) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: 'Slack integration not configured',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const created = await slack.createChannel(body.name)
|
||||||
|
slackChannelId = created.id
|
||||||
|
channelName = created.name
|
||||||
|
} catch (err) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 502,
|
||||||
|
statusMessage: `Failed to create Slack channel: ${err.data?.error || err.message}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const channel = await BoardChannel.create({
|
const channel = await BoardChannel.create({
|
||||||
name: body.name,
|
name: channelName,
|
||||||
slackChannelId: body.slackChannelId,
|
slackChannelId,
|
||||||
tagSlugs: body.tagSlugs || []
|
tagSlugs: body.tagSlugs || []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,20 @@ export default defineEventHandler(async (event) => {
|
||||||
if (body.slackChannelId !== undefined) updateData.slackChannelId = body.slackChannelId
|
if (body.slackChannelId !== undefined) updateData.slackChannelId = body.slackChannelId
|
||||||
if (body.tagSlugs !== undefined) updateData.tagSlugs = body.tagSlugs
|
if (body.tagSlugs !== undefined) updateData.tagSlugs = body.tagSlugs
|
||||||
|
|
||||||
|
if (body.tagSlugs && body.tagSlugs.length) {
|
||||||
|
const conflict = await BoardChannel.findOne({
|
||||||
|
_id: { $ne: id },
|
||||||
|
tagSlugs: { $in: body.tagSlugs },
|
||||||
|
}).lean()
|
||||||
|
if (conflict) {
|
||||||
|
const taken = (conflict.tagSlugs || []).filter((s) => body.tagSlugs.includes(s))
|
||||||
|
throw createError({
|
||||||
|
statusCode: 409,
|
||||||
|
statusMessage: `Tag${taken.length > 1 ? 's' : ''} already mapped to "${conflict.name}": ${taken.join(', ')}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const channel = await BoardChannel.findByIdAndUpdate(
|
const channel = await BoardChannel.findByIdAndUpdate(
|
||||||
id,
|
id,
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,7 @@ export const boardPostUpdateSchema = z.object({
|
||||||
|
|
||||||
export const boardChannelCreateSchema = z.object({
|
export const boardChannelCreateSchema = z.object({
|
||||||
name: z.string().trim().min(1).max(200),
|
name: z.string().trim().min(1).max(200),
|
||||||
slackChannelId: z.string().trim().min(1).max(50).regex(/^[A-Z0-9]+$/, 'Invalid Slack channel ID'),
|
slackChannelId: z.string().trim().min(1).max(50).regex(/^[A-Z0-9]+$/, 'Invalid Slack channel ID').optional(),
|
||||||
tagSlugs: z.array(z.string().max(100)).optional().default([])
|
tagSlugs: z.array(z.string().max(100)).optional().default([])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -262,6 +262,33 @@ export class SlackService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Slack channel. Returns the new channel id and normalized name.
|
||||||
|
*/
|
||||||
|
async createChannel(
|
||||||
|
name: string,
|
||||||
|
isPrivate: boolean = false,
|
||||||
|
): Promise<{ id: string; name: string }> {
|
||||||
|
const normalized = name
|
||||||
|
.trim()
|
||||||
|
.replace(/^#/, '')
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9_-]+/g, '-')
|
||||||
|
.replace(/^-+|-+$/g, '')
|
||||||
|
.slice(0, 80)
|
||||||
|
|
||||||
|
const response = await this.client.conversations.create({
|
||||||
|
name: normalized,
|
||||||
|
is_private: isPrivate,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.ok || !response.channel?.id || !response.channel?.name) {
|
||||||
|
throw new Error(`Slack create failed: ${response.error || 'unknown'}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { id: response.channel.id, name: response.channel.name }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify the Slack channel exists and bot has access
|
* Verify the Slack channel exists and bot has access
|
||||||
*/
|
*/
|
||||||
|
|
@ -292,3 +319,36 @@ export function getSlackService(): SlackService | null {
|
||||||
|
|
||||||
return new SlackService(config.slackBotToken, config.slackVettingChannelId);
|
return new SlackService(config.slackBotToken, config.slackVettingChannelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a SlackService for operations that don't need the vetting channel.
|
||||||
|
*/
|
||||||
|
export function getSlackServiceNoVetting(): SlackService | null {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
|
||||||
|
if (!config.slackBotToken) {
|
||||||
|
console.warn("Slack integration not configured - missing bot token");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SlackService(config.slackBotToken, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a SlackService backed by the AdminGhost app token for admin-only
|
||||||
|
* operations like channel creation. Falls back to the main bot token if
|
||||||
|
* AdminGhost isn't configured.
|
||||||
|
*/
|
||||||
|
export function getSlackAdminService(): SlackService | null {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
|
||||||
|
const token = config.slackAdminBotToken || config.slackBotToken;
|
||||||
|
if (!token) {
|
||||||
|
console.warn(
|
||||||
|
"Slack admin integration not configured - missing admin bot token",
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SlackService(token, "");
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ import { setResponseStatus } from 'h3'
|
||||||
|
|
||||||
vi.stubGlobal('setResponseStatus', setResponseStatus)
|
vi.stubGlobal('setResponseStatus', setResponseStatus)
|
||||||
|
|
||||||
const { mockFind, mockCreate, mockFindByIdAndUpdate, mockFindByIdAndDelete } = vi.hoisted(() => ({
|
const { mockFind, mockFindOne, mockCreate, mockFindByIdAndUpdate, mockFindByIdAndDelete } = vi.hoisted(() => ({
|
||||||
mockFind: vi.fn(),
|
mockFind: vi.fn(),
|
||||||
|
mockFindOne: vi.fn(),
|
||||||
mockCreate: vi.fn(),
|
mockCreate: vi.fn(),
|
||||||
mockFindByIdAndUpdate: vi.fn(),
|
mockFindByIdAndUpdate: vi.fn(),
|
||||||
mockFindByIdAndDelete: vi.fn(),
|
mockFindByIdAndDelete: vi.fn(),
|
||||||
|
|
@ -13,6 +14,7 @@ const { mockFind, mockCreate, mockFindByIdAndUpdate, mockFindByIdAndDelete } = v
|
||||||
vi.mock('../../../server/models/boardChannel.js', () => ({
|
vi.mock('../../../server/models/boardChannel.js', () => ({
|
||||||
default: {
|
default: {
|
||||||
find: mockFind,
|
find: mockFind,
|
||||||
|
findOne: mockFindOne,
|
||||||
create: mockCreate,
|
create: mockCreate,
|
||||||
findByIdAndUpdate: mockFindByIdAndUpdate,
|
findByIdAndUpdate: mockFindByIdAndUpdate,
|
||||||
findByIdAndDelete: mockFindByIdAndDelete,
|
findByIdAndDelete: mockFindByIdAndDelete,
|
||||||
|
|
@ -37,6 +39,16 @@ vi.mock('../../../server/utils/mongoose.js', () => ({
|
||||||
connectDB: vi.fn(),
|
connectDB: vi.fn(),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const { mockCreateSlackChannel } = vi.hoisted(() => ({
|
||||||
|
mockCreateSlackChannel: vi.fn(),
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('../../../server/utils/slack.ts', () => ({
|
||||||
|
getSlackServiceNoVetting: () => ({
|
||||||
|
createChannel: mockCreateSlackChannel,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
import { requireAuth, requireAdmin } from '../../../server/utils/auth.js'
|
import { requireAuth, requireAdmin } from '../../../server/utils/auth.js'
|
||||||
import { validateBody } from '../../../server/utils/validateBody.js'
|
import { validateBody } from '../../../server/utils/validateBody.js'
|
||||||
import getHandler from '../../../server/api/board/channels.get.js'
|
import getHandler from '../../../server/api/board/channels.get.js'
|
||||||
|
|
@ -80,6 +92,7 @@ describe('POST /api/admin/board-channels', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
requireAdmin.mockResolvedValue({ _id: 'admin-1', role: 'admin' })
|
requireAdmin.mockResolvedValue({ _id: 'admin-1', role: 'admin' })
|
||||||
|
mockFindOne.mockReturnValue({ lean: vi.fn().mockResolvedValue(null) })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('creates channel when admin sends valid data', async () => {
|
it('creates channel when admin sends valid data', async () => {
|
||||||
|
|
@ -145,12 +158,66 @@ describe('POST /api/admin/board-channels', () => {
|
||||||
const event = createMockEvent({ method: 'POST', path: '/api/admin/board-channels' })
|
const event = createMockEvent({ method: 'POST', path: '/api/admin/board-channels' })
|
||||||
await expect(postHandler(event)).rejects.toMatchObject({ statusCode: 409 })
|
await expect(postHandler(event)).rejects.toMatchObject({ statusCode: 409 })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('creates Slack channel via API when slackChannelId not provided', async () => {
|
||||||
|
validateBody.mockResolvedValue({
|
||||||
|
name: 'coop-formation',
|
||||||
|
tagSlugs: [],
|
||||||
|
})
|
||||||
|
mockCreateSlackChannel.mockResolvedValue({ id: 'C_NEW_123', name: 'coop-formation' })
|
||||||
|
const created = {
|
||||||
|
_id: 'new-ch',
|
||||||
|
name: 'coop-formation',
|
||||||
|
slackChannelId: 'C_NEW_123',
|
||||||
|
tagSlugs: [],
|
||||||
|
toObject() {
|
||||||
|
return {
|
||||||
|
_id: this._id,
|
||||||
|
name: this.name,
|
||||||
|
slackChannelId: this.slackChannelId,
|
||||||
|
tagSlugs: this.tagSlugs,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
mockCreate.mockResolvedValue(created)
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'POST', path: '/api/admin/board-channels' })
|
||||||
|
const result = await postHandler(event)
|
||||||
|
|
||||||
|
expect(mockCreateSlackChannel).toHaveBeenCalledWith('coop-formation')
|
||||||
|
expect(mockCreate).toHaveBeenCalledWith({
|
||||||
|
name: 'coop-formation',
|
||||||
|
slackChannelId: 'C_NEW_123',
|
||||||
|
tagSlugs: [],
|
||||||
|
})
|
||||||
|
expect(result.channel.slackChannelId).toBe('C_NEW_123')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns 409 when a tag is already mapped to another channel', async () => {
|
||||||
|
validateBody.mockResolvedValue({
|
||||||
|
name: 'new-ch',
|
||||||
|
slackChannelId: 'C99999',
|
||||||
|
tagSlugs: ['coop-formation'],
|
||||||
|
})
|
||||||
|
mockFindOne.mockReturnValue({
|
||||||
|
lean: vi.fn().mockResolvedValue({
|
||||||
|
_id: 'existing',
|
||||||
|
name: 'old-ch',
|
||||||
|
tagSlugs: ['coop-formation'],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'POST', path: '/api/admin/board-channels' })
|
||||||
|
await expect(postHandler(event)).rejects.toMatchObject({ statusCode: 409 })
|
||||||
|
expect(mockCreate).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('PATCH /api/admin/board-channels/[id]', () => {
|
describe('PATCH /api/admin/board-channels/[id]', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
requireAdmin.mockResolvedValue({ _id: 'admin-1', role: 'admin' })
|
requireAdmin.mockResolvedValue({ _id: 'admin-1', role: 'admin' })
|
||||||
|
mockFindOne.mockReturnValue({ lean: vi.fn().mockResolvedValue(null) })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates a channel', async () => {
|
it('updates a channel', async () => {
|
||||||
|
|
@ -187,6 +254,23 @@ describe('PATCH /api/admin/board-channels/[id]', () => {
|
||||||
await expect(patchHandler(event)).rejects.toMatchObject({ statusCode: 404 })
|
await expect(patchHandler(event)).rejects.toMatchObject({ statusCode: 404 })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('returns 409 when PATCH assigns a tag already owned by another channel', async () => {
|
||||||
|
validateBody.mockResolvedValue({ tagSlugs: ['coop-formation'] })
|
||||||
|
mockFindOne.mockReturnValue({
|
||||||
|
lean: vi.fn().mockResolvedValue({
|
||||||
|
_id: 'other',
|
||||||
|
name: 'other-ch',
|
||||||
|
tagSlugs: ['coop-formation'],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'PATCH', path: '/api/admin/board-channels/c1' })
|
||||||
|
event.context = { params: { id: 'c1' } }
|
||||||
|
|
||||||
|
await expect(patchHandler(event)).rejects.toMatchObject({ statusCode: 409 })
|
||||||
|
expect(mockFindByIdAndUpdate).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
it('rejects non-admin with 403', async () => {
|
it('rejects non-admin with 403', async () => {
|
||||||
requireAdmin.mockRejectedValue(
|
requireAdmin.mockRejectedValue(
|
||||||
createError({ statusCode: 403, statusMessage: 'Forbidden' }),
|
createError({ statusCode: 403, statusMessage: 'Forbidden' }),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue