-
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
Addressing issue with first timers adding tags. #9829
Addressing issue with first timers adding tags. #9829
Conversation
Thanks for opening this pull request! This space is protected by our Code of Conduct - and we're here to help. |
app/models/node.rb
Outdated
@@ -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') |
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.
Consider simplifying this complex logical expression.
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 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.
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 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 :)
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 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?
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.
@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 ¯_(ツ)_/¯
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.
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!
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? |
@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 |
Sounds great @17sushmita |
Codecov Report
@@ Coverage Diff @@
## main #9829 +/- ##
=======================================
Coverage ? 79.57%
=======================================
Files ? 98
Lines ? 5962
Branches ? 0
=======================================
Hits ? 4744
Misses ? 1218
Partials ? 0 |
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!!! |
Code Climate has analyzed commit 734c5b8 and detected 5 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
@RuthNjeri @jywarren, I've added a commit to fix the failing tests and opening a new PR to add tests for this functionality. |
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.
LGTM🎉🎉
Congrats on merging your first pull request! 🙌🎉⚡️ Help others take their first stepNow that you've merged your first pull request, you're the perfect person to help someone else out with this challenging first step. 🙌 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. |
Awesome. Great work @lonwabo-mnyaiza and thanks @17sushmita !! |
* 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>
…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>
* 🐛 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>
…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>
* 🐛 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>
…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>
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!
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