Merge pull request #3953 from techAPJ/wiki

FEATURE: allow users to wikify their own posts based on trust level
This commit is contained in:
Arpit Jalan
2016-01-13 09:53:33 +05:30
10 changed files with 65 additions and 21 deletions

View File

@@ -349,6 +349,21 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
this.sendAction('toggleBookmark', post);
},
// Wiki button
buttonForWiki(post) {
if (!post.get('can_wiki')) return;
if (post.get('wiki')) {
return new Button('wiki', 'post.controls.unwiki', 'pencil-square-o', {className: 'wiki wikied'});
} else {
return new Button('wiki', 'post.controls.wiki', 'pencil-square-o', {className: 'wiki'});
}
},
clickWiki(post) {
this.sendAction('toggleWiki', post);
},
buttonForAdmin() {
if (!Discourse.User.currentProp('canManageTopic')) { return; }
return new Button('admin', 'post.controls.admin', 'wrench');
@@ -357,10 +372,7 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
renderAdminPopup(post, buffer) {
if (!Discourse.User.currentProp('canManageTopic')) { return; }
const isWiki = post.get('wiki'),
wikiIcon = iconHTML('pencil-square-o'),
wikiText = isWiki ? I18n.t('post.controls.unwiki') : I18n.t('post.controls.wiki'),
isModerator = post.get('post_type') === this.site.get('post_types.moderator_action'),
const isModerator = post.get('post_type') === this.site.get('post_types.moderator_action'),
postTypeIcon = iconHTML('shield'),
postTypeText = isModerator ? I18n.t('post.controls.revert_to_regular') : I18n.t('post.controls.convert_to_moderator'),
rebakePostIcon = iconHTML('cog'),
@@ -373,7 +385,6 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
const html = '<div class="post-admin-menu popup-menu">' +
'<h3>' + I18n.t('admin_title') + '</h3>' +
'<ul>' +
'<li class="btn" data-action="toggleWiki">' + wikiIcon + wikiText + '</li>' +
(Discourse.User.currentProp('staff') ? '<li class="btn" data-action="togglePostType">' + postTypeIcon + postTypeText + '</li>' : '') +
'<li class="btn" data-action="rebakePost">' + rebakePostIcon + rebakePostText + '</li>' +
(post.hidden ? '<li class="btn" data-action="unhidePost">' + unhidePostIcon + unhidePostText + '</li>' : '') +
@@ -393,10 +404,6 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
});
},
clickToggleWiki() {
this.sendAction('toggleWiki', this.get('post'));
},
clickTogglePostType() {
this.sendAction("togglePostType", this.get("post"));
},

View File

@@ -174,6 +174,10 @@ nav.post-controls {
box-shadow: none;
}
&.wikied {
color: green;
}
&.bookmark {padding: 8px 11px; }
.read-icon {

View File

@@ -58,6 +58,7 @@ button {
margin:10px 0 10px 0;
}
&.has-like {color: $love;}
&.wikied { color: green; }
.read-icon {
&:before {
font-family: "FontAwesome";

View File

@@ -305,9 +305,9 @@ class PostsController < ApplicationController
end
def wiki
guardian.ensure_can_wiki!
post = find_post_from_params
guardian.ensure_can_wiki!(post)
post.revise(current_user, { wiki: params[:wiki] })
render nothing: true

View File

@@ -38,6 +38,7 @@ class PostSerializer < BasicPostSerializer
:can_edit,
:can_delete,
:can_recover,
:can_wiki,
:link_counts,
:read,
:user_title,
@@ -130,6 +131,10 @@ class PostSerializer < BasicPostSerializer
scope.can_recover_post?(object)
end
def can_wiki
scope.can_wiki?(object)
end
def display_username
object.user.try(:name)
end