From 7a394b8e90be126f9bec03519a3bc8d01993eef9 Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Sat, 26 Jan 2019 23:42:52 +0300 Subject: [PATCH 1/2] support positive score only mode --- web/app/components/comment/comment.jsx | 51 +++++++++++++++++++------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/web/app/components/comment/comment.jsx b/web/app/components/comment/comment.jsx index d04fed3c6f..7c7a209ff3 100644 --- a/web/app/components/comment/comment.jsx +++ b/web/app/components/comment/comment.jsx @@ -45,7 +45,8 @@ export default class Comment extends Component { this.isAdmin = this.isAdmin.bind(this); this.isCurrentUser = this.isCurrentUser.bind(this); this.isGuest = this.isGuest.bind(this); - this.getVoteDisabledReason = this.getVoteDisabledReason.bind(this); + this.getUpvoteDisabledReason = this.getUpvoteDisabledReason.bind(this); + this.getDownvoteDisabledReason = this.getDownvoteDisabledReason.bind(this); } componentWillReceiveProps(nextProps) { @@ -359,7 +360,23 @@ export default class Comment extends Component { * * @return {(string|null)} */ - getVoteDisabledReason() { + getDownvoteDisabledReason() { + if (this.props.mods && this.props.mods.view === 'user') return 'Voting disabled in last comments'; + if (this.isGuest()) return 'Only authorized users are allowed to vote'; + const info = store.get('info'); + if (info && info.read_only) return "You can't vote on read-only topics"; + if (this.isCurrentUser()) return "You can't vote for your own comment"; + const config = store.get('config') || {}; + if (config.positive_score && this.state.score < 1) return 'Only positive score allowed'; + return null; + } + + /** + * returns reason for disabled voting + * + * @return {(string|null)} + */ + getUpvoteDisabledReason() { if (this.props.mods && this.props.mods.view === 'user') return 'Voting disabled in last comments'; if (this.isGuest()) return 'Only authorized users are allowed to vote'; const info = store.get('info'); @@ -389,10 +406,14 @@ export default class Comment extends Component { const isGuest = this.isGuest(); const isCurrentUser = this.isCurrentUser(); const config = store.get('config') || {}; + const lowCommentScore = config.low_score; - const votingDisabledReason = this.getVoteDisabledReason(); - const isVotingDisabled = votingDisabledReason !== null; + const downvotingDisabledReason = this.getDownvoteDisabledReason(); + const isDownvotingDisabled = downvotingDisabledReason !== null; + const upvotingDisabledReason = this.getUpvoteDisabledReason(); + const isUpvotingDisabled = upvotingDisabledReason !== null; const editable = data.repliesCount === 0 && !!editTimeLeft; + const scoreSignEnabled = !config.positive_score; const o = { ...data, @@ -416,7 +437,7 @@ export default class Comment extends Component { : data.orig, score: { value: Math.abs(score), - sign: score > 0 ? '+' : score < 0 ? 'βˆ’' : null, + sign: !scoreSignEnabled ? '' : score > 0 ? '+' : score < 0 ? 'βˆ’' : null, view: score > 0 ? 'positive' : score < 0 ? 'negative' : null, }, user: { @@ -541,10 +562,14 @@ export default class Comment extends Component { Vote up @@ -558,11 +583,11 @@ export default class Comment extends Component { className={b( 'comment__vote', {}, - { type: 'down', selected: scoreDecreased, disabled: isVotingDisabled } + { type: 'down', selected: scoreDecreased, disabled: isDownvotingDisabled } )} - aria-disabled={isVotingDisabled ? 'true' : 'false'} - {...getHandleClickProps(isVotingDisabled ? null : this.decreaseScore)} - title={votingDisabledReason} + aria-disabled={isDownvotingDisabled ? 'true' : 'false'} + {...getHandleClickProps(isDownvotingDisabled ? null : this.decreaseScore)} + title={downvotingDisabledReason} > Vote down From 24f0c301d3f32f803b328f2e71e5f1508eb072d2 Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Sun, 27 Jan 2019 01:23:04 +0300 Subject: [PATCH 2/2] update readme --- README.md | 59 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index a9fe07e239..c1c0264ee0 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ Remark42 is a self-hosted, lightweight, and simple (yet functional) comment engi - [Install](#install) - [Backend](#backend) - - [With Docker](#with-docker) - - [Without docker](#without-docker) + - [With Docker](#with-docker) + - [Without docker](#without-docker) - [Parameters](#parameters) - [Required parameters](#required-parameters) - [Register oauth2 providers](#register-oauth2-providers) @@ -77,7 +77,7 @@ _this is the recommended way to run remark42_ #### Without docker * download archive for [stable release](https://github.com/umputun/remark/releases) or [development version](https://remark42.com/downloads) -* unpack with `gunzip` (Linux, macOS) or with `zip` (Windows) +* unpack with `gunzip` (Linux, macOS) or with `zip` (Windows) * run as `remark42.{os}-{arch} server {parameters...}`, i.e. `remark42.linux-amd64 server --secret=12345 --url=http://127.0.0.1:8080` * alternatively compile from the sources - `make OS=[linux|darwin|windows] ARCH=[amd64,386,arm64,arm32]` @@ -114,7 +114,7 @@ _this is the recommended way to run remark42_ | auth.github.csec | AUTH_GITHUB_CSEC | | Github OAuth client secret | | auth.yandex.cid | AUTH_YANDEX_CID | | Yandex OAuth client ID | | auth.yandex.csec | AUTH_YANDEX_CSEC | | Yandex OAuth client secret | -| auth.dev | AUTH_DEV | false | local oauth2 server, development mode only | +| auth.dev | AUTH_DEV | `false` | local oauth2 server, development mode only | | notify.type | NOTIFY_TYPE | none | type of notification (none or telegram) | | notify.queue | NOTIFY_QUEUE | 100 | size of notification queue | | notify.telegram.token | NOTIFY_TELEGRAM_TOKEN | | telegram token | @@ -130,6 +130,7 @@ _this is the recommended way to run remark42_ | max-votes | MAX_VOTES | `-1` | votes limit per comment, `-1` - unlimited | | low-score | LOW_SCORE | `-5` | low score threshold | | critical-score | CRITICAL_SCORE | `-10` | critical score threshold | +| positive-score | POSITIVE_SCORE | `false` | restricts comment's score to be only positive | | restricted-words | RESTRICTED_WORDS | | words banned in comments (can use `*`), _multi_ | | edit-time | EDIT_TIME | `5m` | edit window | | read-age | READONLY_AGE | | read-only age of comments, days | @@ -144,7 +145,7 @@ _this is the recommended way to run remark42_ ##### Required parameters -Most of the parameters have sane defaults and don't require customization. There are only a few parameters user has to define: +Most of the parameters have sane defaults and don't require customization. There are only a few parameters user has to define: 1. `SECRET` - secret key, can be any long and hard-to-guess string. 2. `REMARK_URL` - url pointing to your remark42 server, i.e. `https://demo.reamark42.com` @@ -167,7 +168,7 @@ services: - AUTH_GITHUB_CID=12345667890 # oauth2 client ID - AUTH_GITHUB_CSEC=abcdefg12345678 # oauth2 client secret volumes: - - ./var:/srv/var # persistent volume to store all remark42 data + - ./var:/srv/var # persistent volume to store all remark42 data ``` #### Register oauth2 providers @@ -230,7 +231,7 @@ For more details refer to [Yandex OAuth](https://tech.yandex.com/oauth/doc/dg/co #### Initial import from WordPress -1. Install WordPress [plugin](https://wordpress.org/plugins/wp-exporter/) to export comments and follow it instructions. The plugin should produce a xml-based file with site content including comments. +1. Install WordPress [plugin](https://wordpress.org/plugins/wp-exporter/) to export comments and follow it instructions. The plugin should produce a xml-based file with site content including comments. 2. Move this file to your remark42 host within `./var` 3. Run import command - `docker exec -it remark42 import -p wordpress -f {wordpress-export-name}.xml -s {your site id}` @@ -258,25 +259,25 @@ Restore will clean all comments first and then will processed with complete impo ##### Backup format Backup file is a text file with all exported comments separated by EOL. Each backup record is a valid json with all key/value -unmarshaled from `Comment` struct (see below). +unmarshaled from `Comment` struct (see below). #### Admin users -Admins/moderators should be defined in `docker-compose.yml` as a list of user IDs or passed in the command line. +Admins/moderators should be defined in `docker-compose.yml` as a list of user IDs or passed in the command line. ``` environment: - ADMIN_SHARED_ID=github_ef0f706a79cc24b17bbbb374cd234a691a034128,github_dae9983158e9e5e127ef2b87a411ef13c891e9e5 ``` -To get user id just login and click on your username or any other user you want to promote to admins. +To get user id just login and click on your username or any other user you want to promote to admins. It will expand login info and show full user ID. ### Setup on your website #### Comments -It's a main widget which renders list of comments. +It's a main widget which renders list of comments. Add this snippet to the bottom of web page: @@ -302,7 +303,7 @@ And then add this node in the place where you want to see Remark42 widget: ```html
-``` +``` After that widget will be rendered inside this node. @@ -311,13 +312,13 @@ After that widget will be rendered inside this node. Right now Remark has two themes: light and dark. You can pick one using configuration object, but there is also a possibility to switch between themes in runtime. -For this purpose Remark adds to `window` object named `REMARK42`, +For this purpose Remark adds to `window` object named `REMARK42`, which contains function `changeTheme`. Just call this function and pass a name of the theme that you want to turn on: ```js window.REMARK42.changeTheme('light'); -``` +``` #### Last comments @@ -328,7 +329,7 @@ Add this snippet to the bottom of web page: ```html