mirror of
https://github.com/chenasraf/snpr.git
synced 2026-05-18 01:39:01 +00:00
* Renaming '.env.example' to '.env' * Removing bootstrap gem * Adding newest version of Bootstrap(3.3.6) and setting it up * Renamed 'database.yml.example' to 'database.yml' * Deleted common.css.scss * Deleting active_admin/application requirement * Adding style file that import all style partials and adding javascript file * Updating application.html.erb and includes(footer and navbar) * Removing from news all the updates(new users, new pheno...) and putting on updates page * Updating user views * Updating phenotype views * Updating index page * Updating FAQ and Stats pages * Updating genotype views * Updating messages views * Updating snps views and signin page * Updating fitbit and picture_phenotype views * Updating warning * Adding base style and variable of style * Adding style of index, faq and stats page * Adding style for user views * Adding style for footer and navbar * Adding modules of style * Adding style for fitbit, genotype, phenotype and message views * Adding style for snps and updates views * Updating serverscript * Adding new logo and RSS new image * Adding style files for: comments, password reset, picture phenotypes, achievements and search results * Removing !important and updating some styles * Updating view from achievements * Updating views from fitbit profiles * Updating genotypes views * Updating navbar view * Updating password reset view * Updating phenotype comments views * Updating phenotypes views * Updating views: search result, snps, user phenotypes and users * Updating views: updates and picture phenotypes * Adding updates page's routes * Modify flash messages and change number of fitbit profiles and genotypes per page(20 -> 15) * Replace will_paginate to a version that works with bootstraps * Change serverscript to make Sidekiq work propely * Updates user's views * Updates script to run only when page is fully loaded * Moves script tags to head and updates flash messages' views * Updates and add style for: picture_phenotypes, snps, userpages, press, warnings * Updates views for: genotypes, messages, fitbit_profiles, phenotype comments, phenotypes * Updates views for: picture phenotype, picture phenotype comments, warnings and errors, snps, snps comments * Updates views for: press, picture phenotype user, user session and snps user * Updates views from: user, updates, press and stats * Updates views from: snps, picture phenotypes, phenotypes, genotypes * Updates views from: fitbit profiles, navbar, application, messages and news * Updates script file * Updates style files * Changes modal views * Renaming '.env.example' to '.env' * Removing bootstrap gem * Adding newest version of Bootstrap(3.3.6) and setting it up * Renamed 'database.yml.example' to 'database.yml' * Deleted common.css.scss * Deleting active_admin/application requirement * Adding style file that import all style partials and adding javascript file * Updating application.html.erb and includes(footer and navbar) * Removing from news all the updates(new users, new pheno...) and putting on updates page * Updating user views * Updating phenotype views * Updating index page * Updating FAQ and Stats pages * Updating genotype views * Updating messages views * Updating snps views and signin page * Updating fitbit and picture_phenotype views * Updating warning * Adding base style and variable of style * Adding style of index, faq and stats page * Adding style for user views * Adding style for footer and navbar * Adding modules of style * Adding style for fitbit, genotype, phenotype and message views * Adding style for snps and updates views * Updating serverscript * Adding new logo and RSS new image * Adding style files for: comments, password reset, picture phenotypes, achievements and search results * Removing !important and updating some styles * Updating view from achievements * Updating views from fitbit profiles * Updating genotypes views * Updating navbar view * Updating password reset view * Updating phenotype comments views * Updating phenotypes views * Updating views: search result, snps, user phenotypes and users * Updating views: updates and picture phenotypes * Adding updates page's routes * Modify flash messages and change number of fitbit profiles and genotypes per page(20 -> 15) * Replace will_paginate to a version that works with bootstraps * Change serverscript to make Sidekiq work propely * Updates user's views * Updates script to run only when page is fully loaded * Moves script tags to head and updates flash messages' views * Updates and add style for: picture_phenotypes, snps, userpages, press, warnings * Updates views for: genotypes, messages, fitbit_profiles, phenotype comments, phenotypes * Updates views for: picture phenotype, picture phenotype comments, warnings and errors, snps, snps comments * Updates views for: press, picture phenotype user, user session and snps user * Updates views from: user, updates, press and stats * Updates views from: snps, picture phenotypes, phenotypes, genotypes * Updates views from: fitbit profiles, navbar, application, messages and news * Updates script file * Updates style files * Changes modal views * Updates script file * Add style file for modal * Updates views from: snp comments, user phenotypes, modal and picture phenotypes * Removes empty style files * Moves comments style to modules directory * Creates a more general class for containers and titles * Removing more specific classes for containers and titles * Changes load order, now variables are loaded before base styles * Replaces all containers and titles classes with the more general class for them * Corrects styles order and organization * Updates minimum height for content container * Organizes and refactors script file * Updates views for fitbit and user * Removes 'test-' from all classes and updates some views * Updates settings view * Updates gitignore * Changes config files * Removes some file from .gitignore * Readds the example files * Changes all unnecessary double-quotes to single-quotes * Corrects script file * Updates hound file to ignore JS files * Hopefully merged both * fixes typos, gem installation * Adds missing pagination gem * Deletes Vagrantfile * Automatically replaced all pre Ruby 1.9 hashes with new style to satisfy Hound * More changes for Hound, triggered by me automatically changing the hash syntax * More hound changes * Fully satisfy the hound * Fix some more style issues, delete some old Vagrant stuff * Fix usermailer complaints * Changed some stuff in fitbit notification worker - prob. needs bigger refactor, long lines, cannot change * Two more borked tests * Get rid of useless asset pipeline errors * Skipping search test for now. * added about us here * disclaimer now also for genotypes * working a bit on the hound * fixed FAQ language
276 lines
7.7 KiB
Ruby
276 lines
7.7 KiB
Ruby
# frozen_string_literal: true
|
|
class UsersController < ApplicationController
|
|
|
|
helper_method :sort_column, :sort_direction
|
|
before_filter :require_owner, only: [ :update, :destroy, :edit, :changepassword ]
|
|
before_filter :require_no_user, only: [:new, :create]
|
|
|
|
def new
|
|
@user = User.new
|
|
@title = 'Sign up'
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
format.xml { render xml: @user }
|
|
end
|
|
end
|
|
|
|
def create
|
|
@user = User.new(user_params)
|
|
|
|
if not params[:read]
|
|
flash[:warning] = 'You must tick the box to proceed'
|
|
end
|
|
|
|
if params[:read] && verify_recaptcha(model: @user) && @user.save
|
|
flash[:notice] = 'Account registered'
|
|
UserMailer.welcome_user(@user).deliver_later
|
|
redirect_to @user
|
|
else
|
|
render :new
|
|
end
|
|
end
|
|
|
|
|
|
def index
|
|
# showing all users
|
|
# TODO: Refactor this. - Helge
|
|
@users = User.order(sort_column + ' ' + sort_direction)
|
|
@users_paginate = @users.paginate(page: params[:page], per_page: 10)
|
|
@title = 'Listing all users'
|
|
|
|
if request.format.json?
|
|
@result = []
|
|
begin
|
|
@users = User.all
|
|
@users.each do |u|
|
|
@user = {}
|
|
@user['name'] = u.name
|
|
@user['id'] = u.id
|
|
@user['genotypes'] = []
|
|
Genotype.where(user_id: u.id).each do |g|
|
|
@genotype = {}
|
|
@genotype['id'] = g.id
|
|
@genotype['filetype'] = g.filetype
|
|
@genotype['download_url'] = 'http://opensnp.org/data/' + g.fs_filename
|
|
@user['genotypes'] << @genotype
|
|
end
|
|
@result << @user
|
|
end
|
|
|
|
rescue
|
|
@result = {}
|
|
@result['error'] = 'Sorry, we couldn\'t find any users'
|
|
end
|
|
end
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
format.json { render json: @result }
|
|
end
|
|
end
|
|
|
|
def show
|
|
# showing a single user's page
|
|
@user = User.find_by_id(params[:id]) || not_found
|
|
@title = @user.name + '\'s page'
|
|
@first_name = @user.name.split.first
|
|
@user_phenotypes = @user.user_phenotypes
|
|
@received_messages = @user.messages.where(sent: false).order('created_at DESC')
|
|
@sent_messages = @user.messages.where(sent: true).order('created_at DESC')
|
|
@phenotype_comments = PhenotypeComment.where(user_id: @user.id).paginate(page: params[:page])
|
|
@snp_comments = SnpComment.where(user_id: @user.id)
|
|
|
|
# get phenotypes that current_user did not enter yet
|
|
@unentered_phenotypes = Phenotype.all - @user.phenotypes
|
|
@unentered_phenotypes = @unentered_phenotypes.shuffle
|
|
@unentered_phenotypes = @unentered_phenotypes[0..20]
|
|
|
|
#find all snp-comment-replies that this user got
|
|
@user_snp_comment_ids = []
|
|
@snp_comments.each do |sc| @user_snp_comment_ids << sc.id end
|
|
@snp_comment_replies = []
|
|
@user_snp_comment_ids.each do |ui|
|
|
@replies_for_snp = SnpComment.where(reply_to_id: ui)
|
|
@replies_for_snp.each do |rs|
|
|
@snp_comment_replies << rs
|
|
end
|
|
end
|
|
@snp_comment_replies.sort! { |b,a| a.created_at <=> b.created_at }
|
|
@paginated_snp_replies = @snp_comment_replies
|
|
|
|
#find all phenotype-comment-replies that this user got
|
|
@user_phenotype_comment_ids = []
|
|
@phenotype_comments.each do |pc| @user_phenotype_comment_ids << pc.id end
|
|
@phenotype_comment_replies = []
|
|
@user_phenotype_comment_ids.each do |pi|
|
|
@replies_for_phenotype = PhenotypeComment.where(reply_to_id: pi).all
|
|
@replies_for_phenotype.each do |rp|
|
|
@phenotype_comment_replies << rp
|
|
end
|
|
end
|
|
@phenotype_comment_replies.sort! { |b,a| a.created_at <=> b.created_at }
|
|
@paginated_phenotype_replies = @phenotype_comment_replies
|
|
|
|
@last_30_papers = LastUpdatedSnpsService.get_last_thirty_updated_snps(@user)
|
|
respond_to do |format|
|
|
format.html
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@user = User.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html
|
|
format.xml
|
|
end
|
|
end
|
|
|
|
def changepassword
|
|
@user = User.find_by_id(params[:id])
|
|
end
|
|
|
|
def update
|
|
@user = User.find(params[:id])
|
|
|
|
if params[:user][:user_phenotypes_attributes].present?
|
|
params[:user][:user_phenotypes_attributes].each do |p|
|
|
@phenotype = UserPhenotype.find(p[1]["id"]).phenotype
|
|
@old_variation = UserPhenotype.find_by_id(p[1]["id"]).variation
|
|
end
|
|
end
|
|
|
|
if params[:user][:description].present?
|
|
params[:user][:description] = Sanitize.clean(params[:user][:description], Sanitize::Config::RESTRICTED)
|
|
end
|
|
|
|
if @user.update_attributes(user_params)
|
|
@empty_websites = Homepage.where(user_id: current_user.id, url: '')
|
|
@empty_websites.each do |ew| ew.delete end
|
|
|
|
flash[:notice] = "Successfully updated"
|
|
|
|
if params[:user][:password] or params[:user][:avatar]
|
|
redirect_to action: 'edit', id: current_user.id
|
|
else
|
|
respond_to do |format|
|
|
format.js
|
|
format.html
|
|
end
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
format.html do
|
|
if request.xhr?
|
|
flash[:warning] = 'Oooops, something went wrong while editing your details'
|
|
render partial: 'edit'
|
|
else
|
|
render
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def check_to_create_phenotype(characteristic, variation, user_id)
|
|
# does the phenotype exist?
|
|
@phenotype = Phenotype.find_by_characteristic(characteristic)
|
|
if @phenotype == nil
|
|
# createphenotype if it doesn't exist
|
|
@phenotype = Phenotype.create(characteristic: characteristic)
|
|
end
|
|
@user_phenotype = UserPhenotype.find_by_phenotype_id(@phenotype.id)
|
|
if @user_phenotype == nil
|
|
# create user_phenotype if it doesn't exist
|
|
@user_phenotype = UserPhenotype.create(user_id: user_id, variation: variation, phenotype_id: @phenotype.id)
|
|
else
|
|
# if user_phenotype exists, update
|
|
@user_phenotype.update_attributes(variation: variation)
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@user = User.find(params[:id])
|
|
# delete the genotype(s)
|
|
@user.genotypes.each do |ug|
|
|
ug.destroy
|
|
end
|
|
|
|
flash[:notice] = 'Thank you for using openSNP. Goodbye!'
|
|
|
|
# disconnect from fitbit if needed
|
|
if @user.fitbit_profile != nil
|
|
Sidekiq::Client.enqueue(FitbitEndSubscription, @user.fitbit_profile.id)
|
|
end
|
|
|
|
@user.destroy
|
|
|
|
# delete phenotypes without user-phenotypes and update number-of-users
|
|
Sidekiq::Client.enqueue(Fixphenotypes)
|
|
redirect_to root_url
|
|
end
|
|
|
|
def remove_help_one
|
|
current_user.update_attribute("help_one",true)
|
|
render nothing: true
|
|
end
|
|
|
|
def remove_help_two
|
|
current_user.update_attribute("help_two",true)
|
|
render nothing: true
|
|
end
|
|
|
|
def remove_help_three
|
|
current_user.update_attribute("help_three",true)
|
|
render nothing: true
|
|
end
|
|
|
|
private
|
|
|
|
def sort_column
|
|
User.column_names.include?(params[:sort]) ? params[:sort] : 'name'
|
|
end
|
|
|
|
def sort_direction
|
|
%w[desc asc].include?(params[:direction]) ? params[:direction] : 'desc'
|
|
end
|
|
|
|
def require_owner
|
|
unless current_user == User.find(params[:id])
|
|
store_location
|
|
if current_user
|
|
flash[:notice] = 'Redirected to your edit page'
|
|
redirect_to controller: 'users', action: 'edit', id: current_user.id
|
|
else
|
|
flash[:notice] = 'You need to be logged in'
|
|
redirect_to '/signin'
|
|
end
|
|
return false
|
|
end
|
|
end
|
|
|
|
def user_params
|
|
params.require(:user).permit(
|
|
:name,
|
|
:email,
|
|
:password,
|
|
:password_confirmation,
|
|
:avatar,
|
|
:delete_avatar,
|
|
:sex,
|
|
:yearofbirth,
|
|
:description,
|
|
:homepages_attributes,
|
|
:message_on_newsletter,
|
|
:message_on_message,
|
|
:message_on_new_phenotype,
|
|
:message_on_phenotype_comment_reply,
|
|
:message_on_snp_comment_reply,
|
|
user_phenotypes_attributes: [:id, :variation, :_destroy]
|
|
)
|
|
end
|
|
end
|