-
Notifications
You must be signed in to change notification settings - Fork 29
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
Accept terms of use #322
base: develop
Are you sure you want to change the base?
Accept terms of use #322
Conversation
app/controllers/sites_controller.rb
Outdated
if(@site.terms_of_use_content_changed?) | ||
id = current_user.id | ||
users = User.where("id != ?", id) | ||
users.update_all(terms_of_use_accepted: false) |
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 is one possible way of course. What would you think about a solution that uses terms_accepted_at (DateTime)
on a user model - this way you would simply compare updated_at
on Site with the terms_accepted_at
on a model to check whether the user has accepted the updated terms.
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.
Yeah this solution is nice to. I following instructions in task (#317)
And it depend ... if we need to save date of accepted it will be better your solution. but if we wouldn't need it, i think solution with boolean is better .... for example when we need check in DB who accept and who not it will be more readeble when we have this data. Of course we can have both or it is just simple sql query to show it but if we no need date of accept i think it is useles.
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.
Since you introduced terms_of_use_accepted_date the boolean field terms_of_use_accepted is a duplicate. I'd would stay with terms_of_use_accepted_date on the user and simply add a virtual field on user (pseudo code):
def terms_of_use_accepted
user.terms_of_use_accepted_date < site.terms_of_use_accepted_date
end
Then you don't have to update all database rows when the terms change.
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.
yes, good tip. I changed it..
app/controllers/users_controller.rb
Outdated
class UsersController < ApplicationController | ||
|
||
def edit_terms | ||
if(current_user != nil) |
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 project is using cancancan
and devise
- I think there are better ways to ensure the user is not nil or that the user has to be authorized to perform this action.
This of course will work but it's not the cleanest solution.
Also, you could use .nil?
and you don't need to find the user when you have current_user
available in this context - it already has found the user for you.
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 must say i need to look more on cancancan ....
i was repair nil and remove finding user.
app/controllers/users_controller.rb
Outdated
if current_user.is_a?(Mentor) && current_user.kids.empty? | ||
# if a menotr has no kids yet assigned, go to available kids | ||
redirect_to available_kids_path | ||
elsif current_user.is_a?(Teacher) && current_user.mentor_matchings.pluck(:state).include?('pending') |
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 is a way but the performance could be better-using database query -> using where or exists?
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 came out of the solution which is in application_controller.
And i don't understand what you mean with DB query. I thought DB queries are more difficult..
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 I meant something in this manner (using Activerecord) current_user.mentor_matchings.exists?(state: 'pending')
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 this. ok. I changed it. And now question - we have same things in application controller after login. Change it too? I just ask because it is not my code but on the other side it is improve.
@@ -25,4 +25,32 @@ | |||
expect(page).to have_css('h1', text: 'last1, first1') | |||
expect(page).to have_css('h2', text: 'Gesprächsdokumentationen') | |||
end | |||
|
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.
It would be cool to check if
- After updating the terms, the
terms_of_use_accepted
gets reset for other users that have previously accepted the terms - Checking whether the user's
terms_of_use_accepted
change from false to true on the database level
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 the first check what you want is test on line 29 - i create admin and teacher (both with akcepted = true) then i login with admin - did some change in terms of use and save. Logout and login with teacher and check if there is showed page with term of use.
Second check - i tried to do new test in same file on line 57 - similar function but at the end i was reload teacher and check terms_of_use_accepted. Did you mean that?
repairs
Dear @MartinGaher Thanks for your work - very much appreciated! I've checked out the branch and did some acceptance testing. Here are my findings: The following acceptance criteria seems not to be fulfilled: Werden die Nutzungsbedingungen erneut geändert, müssen diese erneut angezeigt und akzeptiert werden In the implementation notes there were some hints how to achive this. Feel free to find another way of implementing it, that fulfills the same criterias: Auf dem site model soll aufgezeichnet, wann die Nutzungsbedingungen das letzte mal geändert wurden. Dies kann z.B. über den "Dirty" state des Feldes gemacht werden: https://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/Dirty.html Auf dem User Model muss ebenfalls aufgezeichnet werden, wann Benutzer*innen das letzte Mal die Nutzungsbedingungen akzeptiert haben. I tested by logging in as admin, accepting the tos, then changing the tos, logging out and login in again. It should have displayed me the tos again but did not. |
Hello @panterch , |
@site.terms_of_use_changed_date = DateTime.now | ||
end | ||
|
||
if @site.save |
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 see one little issue here - What if theoretically speaking saving failed. In this case, we would still set terms_of_use_accepted
to false
for all users.
This is not a big issue but it could maybe be addressed as well.
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's a convention to end date fields with _at
. Maybe you rename this to site.terms_of_use_changed_at
to make the code more readable.
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.
Ok. when i changed logic to dates it is unnecessarily now.
i changed column names to _at
@@ -0,0 +1,5 @@ | |||
class AddTermsOfUseAcceptedDateToUsers < ActiveRecord::Migration[6.1] | |||
def change | |||
add_column :users, :terms_of_use_accepted_date, :datetime |
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's a convention to end date fields with _at. Maybe you rename this to terms_of_use_accepted_at to make the code more readable.
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 changed column names to _at
Change names tos columns in Db, compute accepted from dates + some small changes
Hi, |
Accept term of use after login for all users
After change term of use set status accepted on all users to false.