Initial commit

This commit is contained in:
tshenry 2020-06-18 15:54:01 -07:00
commit ab0078aded
No known key found for this signature in database
GPG Key ID: E2C7B0D57EBBF419
8 changed files with 192 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 tshenry
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# Category Previews
This Discourse theme component will allow you to expose restricted categories without allowing access. The "previews" can link anywhere on or off-site.
More information here:

7
about.json Normal file
View File

@ -0,0 +1,7 @@
{
"name": "Category Previews",
"about_url": null,
"license_url": null,
"component": true,
"minimum_discourse_version": "2.5.0.beta7"
}

View File

@ -0,0 +1,37 @@
import Component from "@ember/component";
import { equal } from "@ember/object/computed";
import discourseComputed from "discourse-common/utils/decorators";
const rawCategoryPreviews = settings.category_previews.split("|");
export default Component.extend({
noCategoryStyle: equal("siteSettings.category_style", "none"),
@discourseComputed()
preview() {
const previewData = [];
const loggedInUser = this.currentUser;
const loggedInUserGroup = loggedInUser ? loggedInUser.groups.map(g => g.name) : [];
const isStaff = loggedInUser ? loggedInUser.staff : false;
const categorySlug = this.args.category.slug;
rawCategoryPreviews.forEach(rawPreview => {
const previewPart = rawPreview.split("~");
const permittedGroup = previewPart[4] ? previewPart[4].split(",") : [];
const hasCategoryAccess = loggedInUserGroup.some(g => permittedGroup.indexOf(g) > -1);
const shouldRender = !loggedInUser || isStaff || !hasCategoryAccess;
if (shouldRender && categorySlug === previewPart[0]) {
previewData.push({
title: previewPart[1],
description: previewPart[2],
href: previewPart[3],
className: `above-${categorySlug}`,
color: settings.border_color
});
}
});
return previewData;
}
});

View File

@ -0,0 +1 @@
{{category-preview tagName="" args=(hash category=category)}}

View File

@ -0,0 +1,67 @@
{{#if preview}}
{{#each preview as |p|}}
{{#if site.mobileView}}
<div style={{border-color p.color}} class="category-list-item category {{p.className}}">
<table class="topic-list">
<tbody>
<tr>
<th class="main-link">
<h3>
{{#if p.href}}
<a class="category-title-link" href={{p.href}}>
<div class="category-text-title">
{{#if (theme-setting 'locked_icon')}}
{{d-icon (theme-setting 'locked_icon')}}
{{/if}}
<span class="category-name">{{p.title}}</span>
</div>
</a>
{{else}}
<div class="category-text-title">
{{#if (theme-setting 'locked_icon')}}
{{d-icon (theme-setting 'locked_icon')}}
{{/if}}
<span class="category-name">{{p.title}}</span>
</div>
{{/if}}
</h3>
</th>
</tr>
<tr class="category-description">
<td colspan="3">
<div class="category-description">{{html-safe p.description}}</div>
</td>
</tr>
</tbody>
</table>
</div>
{{else}}
<tr class={{p.className}}>
<td colspan=2 class="category {{if noCategoryStyle "no-category-style"}}" style={{unless noCategoryStyle (border-color p.color)}}>
<h3>
{{#if p.href}}
<a class="category-title-link" href={{p.href}}>
<div class="category-text-title">
{{#if (theme-setting 'locked_icon')}}
{{d-icon (theme-setting 'locked_icon')}}
{{/if}}
<span class="category-name">{{p.title}}</span>
</div>
</a>
{{else}}
<div class="category-text-title">
{{#if (theme-setting 'locked_icon')}}
{{d-icon (theme-setting 'locked_icon')}}
{{/if}}
<span class="category-name">{{p.title}}</span>
</div>
{{/if}}
</h3>
{{#if p.description}}
<div class="category-description">{{p.description}}</div>
{{/if}}
</td>
</tr>
{{/if}}
{{/each}}
{{/if}}

11
mobile/mobile.scss Normal file
View File

@ -0,0 +1,11 @@
.category-list.with-topics {
.category-list-item[class*="above-"] {
tr.category-description {
display: table-row;
border-bottom: none;
}
div.category-description {
display: block;
}
}
}

43
settings.yml Normal file
View File

@ -0,0 +1,43 @@
---
category_previews:
type: list
list_type: simple
default: ''
description:
en: 'Each entry should be ~ delimited using the following format:
<br><br>
<small><b>category-slug~Preview Name~Preview Description~https://example.com~group</b></small>
<br><br>
<ul>
<li>
category-slug - the preview will display above this category in the category list. The slug can be found by looking at a category URL: https://example.com/c/<b>category-slug</b>/12
<br>
<b>IMPORTANT:</b> The category-slug chosen must be from a category that is visible to everyone.
</li>
<li> Preview Name - the bold, hyperlinked part of the preview</li>
<li>
Preview Description - displayed under the Preview Name
</li>
<li>
https://example.com - the link that will be attached to the Preview Name
</li>
<li>
group - a comma-separated list of group names. Members of these groups will <b>not</b> see the preview. This should align with the category permission settings of the category being previewed.
<br>
<b>IMPORTANT:</b> The groups chosen must configured so that the "Who can see this group?" visibility setting is set to "Group owners, member" or less restrictive.
</li>
</ul>
There should always be 4 "~" in the entry, but you can choose to exclude values after each "~" to omit one of the above sections
<br><br>
You can use the same category slug multiple times. When this is done, the previews will display in the order they appear in the setting.'
locked_icon:
type: string
default: 'lock'
description:
en: 'The name of a Font Awesome icon to display before the Preview Name. Leave blank if no icon is need.'
border_color:
type: string
default: '0088CC'
description:
en: 'The hex color associated with all category previews when the <code>category style</code> site setting is not set to "none."'