-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created a locked tag which can be added to notes by mods / admin #9709
Conversation
Codecov Report
@@ Coverage Diff @@
## main #9709 +/- ##
=======================================
Coverage ? 82.06%
=======================================
Files ? 98
Lines ? 5931
Branches ? 0
=======================================
Hits ? 4867
Misses ? 1064
Partials ? 0 |
@jywarren @RuthNjeri this is how it looks when a normal user tries to delete the 'locked' tag on their content. I've changed the message to Another way of implementing this, is by not giving the |
I love the "can't delete" message you've added. Great work! |
Thanks @jywarren for reviewing! I'll take a look at these suggestions and try implementing them. |
Code Climate has analyzed commit 58e59b8 and detected 0 issues on this pull request. View more on Code Climate. |
@@ -140,7 +140,7 @@ function promptTag(val) { | |||
break; | |||
|
|||
default: | |||
addTag(expr); | |||
addTag(val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not directly related to the 'locked' tag but is required in the promptTag
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, was it a bug from before? Cool. Thanks!
@@ -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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this may be an issue in Firefox, but I could be wrong. I noted this in #9726 too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jywarren I use Firefox and it works fine!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Manasa2850 I just tested the Lock Note
option on the stable site, and on the first click, the reload does not add the tag, I have to click it again or manually reload the page. I am using a chrome browser.
Screen.Recording.2021-06-10.at.17.35.10.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RuthNjeri I'm not really sure why that's happening on the stable site. I tried it out on localhost both on Chrome as well as Firefox and the tag gets added on reload. There's no need to refresh the page.
I'll take a deeper look at this to find out why that's happening on the stable site.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think you need to be an admin to test this out on the stable site, I don't know how to make someone an admin on the stable site, but if you share your username with Jeff, he will be able to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My username on the stable site is Manasa2850.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured out how to make you an admin, you are now one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RuthNjeri I tried it out on stable and this is what I observer
- On Firefox - it works perfectly fine. We don't need to refresh the page for the locked tag to get added.
- On Chrome - sometimes it works fine, without requiring a refresh. But few other times, on clicking the
Lock Note
button, the note gets locked (i.e the lock favicon appears and the Lock Note button goes away) but the 'locked' tag card doesn't appear in the sidebar. We need to refresh the page in order to see it on the sidebar.
I will try to find out why this is happening just on Chrome. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @Manasa2850
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note on Firefox usage. This looks really good and a bit simpler too! Love it!!!
@jywarren I use Firefox and it works fine! |
Sounds great. Merging this! Excellent work! |
@@ -86,6 +86,10 @@ | |||
</table> | |||
<% end %> | |||
|
|||
<% if current_user && ( current_user.role == "admin" || current_user.role == "moderator") && !(@node.has_tag('locked')) %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if, in follow up, we moved this button into the advanced tagging menu? This would then appear on wikis too!
@@ -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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From line 359 above, we have the node_tag
variable derived from this query node_tag = NodeTag.where(nid: params[:nid], tid: params[:tid]).first
,
I am curious as to whether checking to see if node_tag.name != "locked"
will work if the first tag derived is not "locked"
but contains a list of tags like [air-quality, locked]
....the node itself does contain a locked tag but it may not be the first to be picked hence someone else might delete a tag.
Should checking if the tags returned contain "locked"
, before picking the first one in line 359 help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you're totally right, my bad! Yes, let's change this, we can use @node.has_tag('locked')
instead!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Manasa2850 what do you say? Thanks all!
@jywarren I like your idea of moving the lock button to the advanced menu, but I feel it should be there on the main page too since that's a more obvious place for admins / mods to see. Let's have the button in both places. What do you think? @RuthNjeri @jywarren sure I'll put a condition for the 'locked' tag so that it works even when it's not the first one. |
@RuthNjeri @jywarren sorry I might be wrong but line 359 I tried it out when 'locked' is not the first tag and it seems to be working fine. |
Hi Manasa, yes you are right, if someone clicks on the From my understanding, a research note can have many tags and in order to freely delete any of the tags, it must not contain the |
* added test for adding locked tag * admins can add locked tag test * test for admin can add locked tag * added test for moderator * made changes suggested in PR #9709
…liclab#9709) * adding locked tag * normal users can't delete locked tag * changed error message * added javascript function for locking
* added test for adding locked tag * admins can add locked tag test * test for admin can add locked tag * added test for moderator * made changes suggested in PR publiclab#9709
…liclab#9709) * adding locked tag * normal users can't delete locked tag * changed error message * added javascript function for locking
* added test for adding locked tag * admins can add locked tag test * test for admin can add locked tag * added test for moderator * made changes suggested in PR publiclab#9709
Part of #9694
Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!
rake test
@publiclab/reviewers
for help, in a comment belowIf tests do fail, click on the red
X
to learn why by reading the logs.Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software
Thanks!