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

Addressing issue with first timers adding tags. #9829

Conversation

lonwabo-mnyaiza
Copy link
Contributor

@lonwabo-mnyaiza lonwabo-mnyaiza commented Jun 19, 2021

Fixes #9774 (<=== Add issue number here)

This change retricts first time users from adding tags.

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

@welcome
Copy link

welcome bot commented Jun 19, 2021

Thanks for opening this pull request! This space is protected by our Code of Conduct - and we're here to help.
Dangerbot will test out your code and reply in a bit with some pointers and requests.
Also please refer here for installation help 💿
There may be some errors, but don't worry! We'll work through them with you! 👍🎉😄

@gitpod-io
Copy link

gitpod-io bot commented Jun 19, 2021

@@ -1070,6 +1070,8 @@ def can_tag(tagname, user, errors = false)
errors ? I18n.t('node.page_does_not_exist') : false
elsif socials[one_split&.to_sym].present?
errors ? "This tag is used for associating a #{socials[one_split.to_sym]} account. <a href='https://publiclab.org/wiki/oauth'>Click here to read more </a>" : false
elsif user.first_time_poster && !(user.username == self.author.username || (self.coauthors && self.coauthors.exists?(username: user.username)) || user.role == 'admin' || user.role == 'moderator')
Copy link

Choose a reason for hiding this comment

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

Consider simplifying this complex logical expression.

Copy link
Member

Choose a reason for hiding this comment

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

This expression can be changed to

elsif user.first_time_poster && !(user.username == self.author.username || self.coauthors&.exists?(username: user.username) || logged_in_as(['admin', 'moderator']))

which looks a bit more simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't write the test myself, but I think it would be a good idea to have a test around this if one doesn't already exist :)

Copy link
Member

Choose a reason for hiding this comment

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

I can't write the test myself, but I think it would be a good idea to have a test around this if one doesn't already exist :)

Thanks, @lonwabo-mnyaiza I'm already writing the tests. Failing functional tests in this PR were intentional and you don't need to worry but after making this change, I'm not sure why logged_in_as(['admin', 'moderator']) doesn't work here. Maybe it's because can_tag is a property in the models file.

Would you mind changing the last condition to (['admin', 'moderator'].include? user.role) instead of logged_in_as(['admin', 'moderator'])?
The expression would be

    elsif user.first_time_poster && !(user.username == self.author.username || self.coauthors&.exists?(username: user.username) || (['admin', 'moderator'].include? user.role))

Apologies for the last suggested change. Let me know if you need any help.
@RuthNjeri would you like to comment on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@17sushmita regarding the function call to logged_in_as, I'm happy to make the change at 17:00 GTM.
I'm also not 100% sure why it wouldn't work, as it is been used in similar ways on other components ¯_(ツ)_/¯

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @17sushmita and @lonwabo-mnyaiza I think the reason logged_in_as is not working is because it is a function in the applications controller and we are trying to use it in a model file... node.rb...if you want to use it in the node.rb file you need to include the application controller in it which would be a wrong way to connect a controller and model...

The alternative you have provided @17sushmita, (['admin', 'moderator'].include? user.role) looks great!

@RuthNjeri
Copy link
Contributor

Thanks for working on this @lonwabo-mnyaiza 🎉

@17sushmita what do you think about the CodeClimate issues to fix on this PR, should they be addressed?

@17sushmita
Copy link
Member

@lonwabo-mnyaiza, I've suggested a minor change above. Please look into this. And, I think we can ignore the cyclomatic complexity issue as we need all the conditional checks in the can_tag function. What say @RuthNjeri?

@RuthNjeri
Copy link
Contributor

Sounds great @17sushmita

@codecov
Copy link

codecov bot commented Jun 20, 2021

Codecov Report

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

❗ Current head 32958e3 differs from pull request most recent head 734c5b8. Consider uploading reports for the commit 734c5b8 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9829   +/-   ##
=======================================
  Coverage        ?   79.57%           
=======================================
  Files           ?       98           
  Lines           ?     5962           
  Branches        ?        0           
=======================================
  Hits            ?     4744           
  Misses          ?     1218           
  Partials        ?        0           

@jywarren
Copy link
Member

Hi all! I'm bypassing the remaining CodeClimate recommendations, as @17sushmita noted, and can you just link to the PR which contains the fix for this? Or, @17sushmita will you be opening a pull request against the branch https://github.com/lonwabo-mnyaiza/plots2/tree/fix/block-first-timers-from-adding-tags so that once it's merged, this PR will complete tests properly? (if you do, just be sure you mention that PR here, as cross-owner PRs don't always trigger notifications the same way). Thanks, everyone, and great work!!!

@codeclimate
Copy link

codeclimate bot commented Jun 23, 2021

Code Climate has analyzed commit 734c5b8 and detected 5 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2
Style 3

View more on Code Climate.

@17sushmita
Copy link
Member

@RuthNjeri @jywarren, I've added a commit to fix the failing tests and opening a new PR to add tests for this functionality.

Copy link
Member

@17sushmita 17sushmita left a comment

Choose a reason for hiding this comment

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

LGTM🎉🎉

@jywarren jywarren merged commit ba7b7bd into publiclab:main Jun 23, 2021
@welcome
Copy link

welcome bot commented Jun 23, 2021

Congrats on merging your first pull request! 🙌🎉⚡️
Your code will likely be published to PublicLab.org in the next few days, but first it will be published to https://stable.publiclab.org/ (it will take some minutes for this to load, and until then you may see logs from the build process). Please test out your work on this testing server and report back with a comment that all has gone well!
Do join our weekly check-in to share your this week goal and the awesome work you did 😃. Please find the link to our latest check-in here 📝
Now that you've completed this, you can help someone else take their first step!
Reach out to someone else working on theirs on Public Lab's code welcome page (where you'll now be featured as a recent contributor!). Thanks!

Help others take their first step

Now that you've merged your first pull request, you're the perfect person to help someone else out with this challenging first step. 🙌

https://code.publiclab.org

Try looking at this list of `first-timers-only` issues, and see if someone else is waiting for feedback, or even stuck! 😕

People often get stuck at the same steps, so you might be able to help someone get unstuck, or help lead them to some documentation that'd help. Reach out and be encouraging and friendly! 😄 🎉

Read about how to help support another newcomer here, or find other ways to offer mutual support here.

@jywarren
Copy link
Member

Awesome. Great work @lonwabo-mnyaiza and thanks @17sushmita !!

jywarren added a commit that referenced this pull request Jun 29, 2021
* Dropdown fixed

* Fixed button 1

* Button fix 2

* Added helper function to render dropdown buttons

* added space

* Changed function name

* Reduced globe icon count (#9826)

* Reduced globe icon count

* Added equal sign

Co-authored-by: imajit <ajit.171it233@nitk.edu.in>

* Update questionRich.html.erb (#9841)

* Addressing issue with first timers adding tags. (#9829)

* 🐛 minor bug fix, addressing issue with first timers adding tags.

* ♻️ minor refactor, using function call to compare user role.

* ♻️🔥 remove logged_in_as function call in conditional statement.

* fixing failing tests by blocking first time posters from adding tags

Co-authored-by: 17sushmita <17sushmita@gmail.com>

* Dropdown fixed

* Fixed button 1

* Button fix 2

* Added helper function to render dropdown buttons

* added space

* Changed function name

Co-authored-by: imajit <ajit.171it233@nitk.edu.in>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
Co-authored-by: lonwabo <60598841+lonwabo-mnyaiza@users.noreply.github.com>
Co-authored-by: 17sushmita <17sushmita@gmail.com>
17sushmita added a commit to 17sushmita/plots2 that referenced this pull request Jul 7, 2021
…ab#9810)

* Dropdown fixed

* Fixed button 1

* Button fix 2

* Added helper function to render dropdown buttons

* added space

* Changed function name

* Reduced globe icon count (publiclab#9826)

* Reduced globe icon count

* Added equal sign

Co-authored-by: imajit <ajit.171it233@nitk.edu.in>

* Update questionRich.html.erb (publiclab#9841)

* Addressing issue with first timers adding tags. (publiclab#9829)

* 🐛 minor bug fix, addressing issue with first timers adding tags.

* ♻️ minor refactor, using function call to compare user role.

* ♻️🔥 remove logged_in_as function call in conditional statement.

* fixing failing tests by blocking first time posters from adding tags

Co-authored-by: 17sushmita <17sushmita@gmail.com>

* Dropdown fixed

* Fixed button 1

* Button fix 2

* Added helper function to render dropdown buttons

* added space

* Changed function name

Co-authored-by: imajit <ajit.171it233@nitk.edu.in>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
Co-authored-by: lonwabo <60598841+lonwabo-mnyaiza@users.noreply.github.com>
Co-authored-by: 17sushmita <17sushmita@gmail.com>
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
* 🐛 minor bug fix, addressing issue with first timers adding tags.

* ♻️ minor refactor, using function call to compare user role.

* ♻️🔥 remove logged_in_as function call in conditional statement.

* fixing failing tests by blocking first time posters from adding tags

Co-authored-by: 17sushmita <17sushmita@gmail.com>
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
…ab#9810)

* Dropdown fixed

* Fixed button 1

* Button fix 2

* Added helper function to render dropdown buttons

* added space

* Changed function name

* Reduced globe icon count (publiclab#9826)

* Reduced globe icon count

* Added equal sign

Co-authored-by: imajit <ajit.171it233@nitk.edu.in>

* Update questionRich.html.erb (publiclab#9841)

* Addressing issue with first timers adding tags. (publiclab#9829)

* 🐛 minor bug fix, addressing issue with first timers adding tags.

* ♻️ minor refactor, using function call to compare user role.

* ♻️🔥 remove logged_in_as function call in conditional statement.

* fixing failing tests by blocking first time posters from adding tags

Co-authored-by: 17sushmita <17sushmita@gmail.com>

* Dropdown fixed

* Fixed button 1

* Button fix 2

* Added helper function to render dropdown buttons

* added space

* Changed function name

Co-authored-by: imajit <ajit.171it233@nitk.edu.in>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
Co-authored-by: lonwabo <60598841+lonwabo-mnyaiza@users.noreply.github.com>
Co-authored-by: 17sushmita <17sushmita@gmail.com>
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
* 🐛 minor bug fix, addressing issue with first timers adding tags.

* ♻️ minor refactor, using function call to compare user role.

* ♻️🔥 remove logged_in_as function call in conditional statement.

* fixing failing tests by blocking first time posters from adding tags

Co-authored-by: 17sushmita <17sushmita@gmail.com>
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
…ab#9810)

* Dropdown fixed

* Fixed button 1

* Button fix 2

* Added helper function to render dropdown buttons

* added space

* Changed function name

* Reduced globe icon count (publiclab#9826)

* Reduced globe icon count

* Added equal sign

Co-authored-by: imajit <ajit.171it233@nitk.edu.in>

* Update questionRich.html.erb (publiclab#9841)

* Addressing issue with first timers adding tags. (publiclab#9829)

* 🐛 minor bug fix, addressing issue with first timers adding tags.

* ♻️ minor refactor, using function call to compare user role.

* ♻️🔥 remove logged_in_as function call in conditional statement.

* fixing failing tests by blocking first time posters from adding tags

Co-authored-by: 17sushmita <17sushmita@gmail.com>

* Dropdown fixed

* Fixed button 1

* Button fix 2

* Added helper function to render dropdown buttons

* added space

* Changed function name

Co-authored-by: imajit <ajit.171it233@nitk.edu.in>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
Co-authored-by: lonwabo <60598841+lonwabo-mnyaiza@users.noreply.github.com>
Co-authored-by: 17sushmita <17sushmita@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Block requests to add tags by first time poster from backend
4 participants