Skip to content

Commit

Permalink
Created a locked tag which can be added to notes by mods / admin (#9709)
Browse files Browse the repository at this point in the history
* adding locked tag

* normal users can't delete locked tag

* changed error message

* added javascript function for locking
  • Loading branch information
Manasa2850 authored Jun 3, 2021
1 parent 431f586 commit 6ad3102
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/tagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function promptTag(val) {
break;

default:
addTag(expr);
addTag(val);
break;

}
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def delete
node_tag = NodeTag.where(nid: params[:nid], tid: params[:tid]).first
node = Node.where(nid: params[:nid]).first
# only admins, mods, and tag authors can delete other peoples' tags
if node_tag.uid == current_user.uid || logged_in_as(['admin', 'moderator']) || node.uid == current_user.uid
if node_tag.uid == current_user.uid || logged_in_as(['admin', 'moderator']) || (node.uid == current_user.uid && node_tag.name != "locked")

tag = Tag.joins(:node_tag)
.select('term_data.name')
Expand All @@ -385,6 +385,9 @@ def delete
end
end
end
elsif node_tag.name == "locked"
flash[:error] = "Only admins can delete the locked tag."
redirect_to Node.find_by(nid: params[:nid]).path
else
flash[:error] = I18n.t('tag_controller.must_own_tag_to_delete')
redirect_to Node.find_by(nid: params[:nid]).path
Expand Down
4 changes: 4 additions & 0 deletions app/views/notes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
</table>
<% end %>

<% if current_user && ( current_user.role == "admin" || current_user.role == "moderator") && !(@node.has_tag('locked')) %>
<a href="javascript:window.location.reload(true)" onClick="addTag('locked');">Lock Note</a>
<% end %>

<% if current_user &&
( current_user.role == "admin" || current_user.role == "moderator" ||
current_user.id == @node.id || current_user.is_coauthor?(@node) ) &&
Expand Down

0 comments on commit 6ad3102

Please sign in to comment.