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

Accept terms of use #322

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

gahermar
Copy link

Accept term of use after login for all users
After change term of use set status accepted on all users to false.

if(@site.terms_of_use_content_changed?)
id = current_user.id
users = User.where("id != ?", id)
users.update_all(terms_of_use_accepted: false)

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.

Copy link
Author

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.

Copy link
Owner

@panterch panterch Mar 23, 2022

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.

Copy link
Author

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

class UsersController < ApplicationController

def edit_terms
if(current_user != nil)

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.

Copy link
Author

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.

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')

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?

Copy link
Author

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

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')

Copy link
Author

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

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

Copy link
Author

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?

@panterch
Copy link
Owner

panterch commented Mar 23, 2022

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.

@gahermar
Copy link
Author

Hello @panterch ,
sorry for that. I usually do not enforce accept for user which making changes - it was for all other users. I repair it and now after save app wants to accept too for admin which make changes. I also added datetime to user for check last accepted date and also datetime to site for check last update date.

@site.terms_of_use_changed_date = DateTime.now
end

if @site.save
Copy link

@jiri1337 jiri1337 Mar 23, 2022

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.

Copy link
Owner

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.

Copy link
Author

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

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.

Copy link
Author

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
@gahermar
Copy link
Author

Hi,
i have question about default values. Now i changed columns in DB to have default values to datetime.now. It is ok or it is better to let it nil and do some check in code? It depends on how is user created. If there is some acceptation during creation or not or if some other user create user account?

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.

None yet

4 participants