Skip to content
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

Merged
merged 4 commits into from
Jun 3, 2021

Conversation

Manasa2850
Copy link
Member

@Manasa2850 Manasa2850 commented May 31, 2021

Part of #9694

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/reviewers for help, in a comment below

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If 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!

@gitpod-io
Copy link

gitpod-io bot commented May 31, 2021

@codecov
Copy link

codecov bot commented May 31, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@ece2611). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9709   +/-   ##
=======================================
  Coverage        ?   82.06%           
=======================================
  Files           ?       98           
  Lines           ?     5931           
  Branches        ?        0           
=======================================
  Hits            ?     4867           
  Misses          ?     1064           
  Partials        ?        0           

@Manasa2850
Copy link
Member Author

ezgif com-gif-maker
I would like some suggestions regarding how the 'Lock Note' button should look. Thanks!

@Manasa2850
Copy link
Member Author

Manasa2850 commented May 31, 2021

@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 Only admins can delete the locked tag.
ezgif com-gif-maker

Another way of implementing this, is by not giving the delete tag option to normal users for the 'locked' tag. But this might cause some confusion to users as to why they can't delete tags on their own notes. Please let me know your thoughts regarding this.

config/routes.rb Outdated Show resolved Hide resolved
@jywarren
Copy link
Member

jywarren commented Jun 1, 2021

I love the "can't delete" message you've added. Great work!

@Manasa2850
Copy link
Member Author

Thanks @jywarren for reviewing! I'll take a look at these suggestions and try implementing them.

@codeclimate
Copy link

codeclimate bot commented Jun 2, 2021

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);
Copy link
Member Author

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.

Copy link
Member

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>
Copy link
Member

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!

Copy link
Member Author

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!

Copy link
Contributor

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

Copy link
Member Author

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.
ezgif com-gif-maker

I'll take a deeper look at this to find out why that's happening on the stable site.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

@Manasa2850 Manasa2850 Jun 11, 2021

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

  1. On Firefox - it works perfectly fine. We don't need to refresh the page for the locked tag to get added.

stable-firefox

  1. 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.

stable-chrome

I will try to find out why this is happening just on Chrome. Thanks!

Copy link
Contributor

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

Copy link
Member

@jywarren jywarren left a 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!!!

@Manasa2850 Manasa2850 requested a review from jywarren June 3, 2021 07:46
@Manasa2850
Copy link
Member Author

@jywarren I use Firefox and it works fine!

@jywarren
Copy link
Member

jywarren commented Jun 3, 2021

Sounds great. Merging this! Excellent work!

@jywarren jywarren merged commit 6ad3102 into publiclab:main Jun 3, 2021
@@ -86,6 +86,10 @@
</table>
<% end %>

<% if current_user && ( current_user.role == "admin" || current_user.role == "moderator") && !(@node.has_tag('locked')) %>
Copy link
Member

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")
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol I was just reviewing this and panicked that I had merged it @jywarren 😅

Are the concerns I have above okay? Or will the tagging work as expected... @jywarren?

Copy link
Member

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!

Copy link
Member

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!

@Manasa2850
Copy link
Member Author

@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.
Thanks!!

@Manasa2850
Copy link
Member Author

@RuthNjeri @jywarren sorry I might be wrong but line 359 node_tag = NodeTag.where(nid: params[:nid], tid: params[:tid]).first refers to the 'locked' tag when we click the delete tag option on the 'locked' tag right? Because tid is unique for every tag we create. So when we click on the delete tag option on the 'locked' tag, node_tag will correspond to the 'locked' tag itself. I don't think it will make a difference whether 'locked' is the first tag in the list of tags or not.

I tried it out when 'locked' is not the first tag and it seems to be working fine.
Please do let me know if I'm missing out on something here. Thanks!

@RuthNjeri
Copy link
Contributor

@RuthNjeri @jywarren sorry I might be wrong but line 359 node_tag = NodeTag.where(nid: params[:nid], tid: params[:tid]).first refers to the 'locked' tag when we click the delete tag option on the 'locked' tag right? Because tid is unique for every tag we create. So when we click on the delete tag option on the 'locked' tag, node_tag will correspond to the 'locked' tag itself. I don't think it will make a difference whether 'locked' is the first tag in the list of tags or not.

I tried it out when 'locked' is not the first tag and it seems to be working fine.
Please do let me know if I'm missing out on something here. Thanks!

Hi Manasa, yes you are right, if someone clicks on the locked tag to try and delete it, the tid in the query will be that of the locked tag. However, let us say a user is trying to delete another tag, lets say air quality and that node, for instance a research note, has the locked tag present, the tag retrieved from the delete is the air quality and it might get deleted because we have not checked if the current node has an additional locked tag...

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 locked tag...

Manasa2850 added a commit to Manasa2850/plots2 that referenced this pull request Jun 13, 2021
@Manasa2850 Manasa2850 mentioned this pull request Jun 13, 2021
5 tasks
RuthNjeri pushed a commit that referenced this pull request Jun 20, 2021
* 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
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
…liclab#9709)

* adding locked tag

* normal users can't delete locked tag

* changed error message

* added javascript function for locking
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
* 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
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
…liclab#9709)

* adding locked tag

* normal users can't delete locked tag

* changed error message

* added javascript function for locking
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants