From e8032fd9027435c57572fd0d8bab411841859cbc Mon Sep 17 00:00:00 2001 From: jessib Date: Mon, 23 Dec 2013 16:44:18 -0800 Subject: Initial start to messages API. --- users/app/controllers/v1/messages_controller.rb | 25 +++++++++++++++++++++++++ users/app/models/message.rb | 10 ++++++++++ users/app/models/user_message.rb | 22 ++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 users/app/controllers/v1/messages_controller.rb create mode 100644 users/app/models/message.rb create mode 100644 users/app/models/user_message.rb (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb new file mode 100644 index 0000000..e67e2a3 --- /dev/null +++ b/users/app/controllers/v1/messages_controller.rb @@ -0,0 +1,25 @@ +module V1 + class MessagesController < ApplicationController + + # TODO need to add authentication + respond_to :json + + def user_messages(unseen = true) + user_messages = unseen ? UserMessage.by_user_id_and_seen(:key => [params[:user_id], false]).all : UserMessage.by_user_id(:key => params[:user_id]).all + + messages = [] + user_messages.each do |um| + messages << Message.find(um.message.id) + end + + render json: messages + end + + + # only for PUT + def mark_read + # params[:user_id] params[:message_id] + end + + end +end diff --git a/users/app/models/message.rb b/users/app/models/message.rb new file mode 100644 index 0000000..38fa71e --- /dev/null +++ b/users/app/models/message.rb @@ -0,0 +1,10 @@ +class Message < CouchRest::Model::Base + + use_database :messages + + property :text, String + + design do + end + +end diff --git a/users/app/models/user_message.rb b/users/app/models/user_message.rb new file mode 100644 index 0000000..0b2ce17 --- /dev/null +++ b/users/app/models/user_message.rb @@ -0,0 +1,22 @@ +class UserMessage < CouchRest::Model::Base + + use_database :user_messages + belongs_to :user + belongs_to :message + + validates :user_id, presence: true + validates :message_id, presence: true + + + property :seen, TrueClass, :default => false + + design do + view :by_user_id + view :by_message_id + view :by_user_id_and_seen + own_path = Pathname.new(File.dirname(__FILE__)) + load_views(own_path.join('..', 'designs', 'user_message')) + + end + +end -- cgit v1.2.3 From a9ff52501e9c04edacd250dd94ee3f3ad28cd73d Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 24 Dec 2013 11:13:28 -0800 Subject: API method to mark a user's message as read (will refactor) --- users/app/controllers/v1/messages_controller.rb | 13 +++++++++++-- users/app/models/user_message.rb | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index e67e2a3..a4e9aec 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -4,6 +4,7 @@ module V1 # TODO need to add authentication respond_to :json + # for now, will not pass unseen, so unseen will always be true def user_messages(unseen = true) user_messages = unseen ? UserMessage.by_user_id_and_seen(:key => [params[:user_id], false]).all : UserMessage.by_user_id(:key => params[:user_id]).all @@ -16,9 +17,17 @@ module V1 end - # only for PUT + # routes ensure this is only for PUT def mark_read - # params[:user_id] params[:message_id] + user_message = UserMessage.find_by_user_id_and_message_id([params[:user_id], params[:message_id]]) + user_message.seen = true + + # TODO what to return? + if user_message.save + render json: true + else + render json: false + end end end diff --git a/users/app/models/user_message.rb b/users/app/models/user_message.rb index 0b2ce17..37aae0b 100644 --- a/users/app/models/user_message.rb +++ b/users/app/models/user_message.rb @@ -7,6 +7,8 @@ class UserMessage < CouchRest::Model::Base validates :user_id, presence: true validates :message_id, presence: true + # should not have multiple rows connecting one user to particular message: + validates_uniqueness_of :user_id, :scope => [:message_id] property :seen, TrueClass, :default => false @@ -14,6 +16,7 @@ class UserMessage < CouchRest::Model::Base view :by_user_id view :by_message_id view :by_user_id_and_seen + view :by_user_id_and_message_id own_path = Pathname.new(File.dirname(__FILE__)) load_views(own_path.join('..', 'designs', 'user_message')) -- cgit v1.2.3 From e4390e2ee5b2df20038f12865db462cf1e208ee6 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 24 Dec 2013 12:23:04 -0800 Subject: Add API tests and some refactoring of messages so we can get a user's messages within the webapp. --- users/app/controllers/v1/messages_controller.rb | 10 ++-------- users/app/models/user.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index a4e9aec..fa98042 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -6,14 +6,8 @@ module V1 # for now, will not pass unseen, so unseen will always be true def user_messages(unseen = true) - user_messages = unseen ? UserMessage.by_user_id_and_seen(:key => [params[:user_id], false]).all : UserMessage.by_user_id(:key => params[:user_id]).all - - messages = [] - user_messages.each do |um| - messages << Message.find(um.message.id) - end - - render json: messages + user = User.find(params[:user_id]) + render json: (user ? user.messages : [] ) end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 720f5a9..fe3a127 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -72,6 +72,18 @@ class User < CouchRest::Model::Base Ticket.for_user(self).limit(count).all #defaults to having most recent updated first end + def messages(unseen = true) + + user_messages = unseen ? UserMessage.by_user_id_and_seen(:key => [self.id, false]).all : UserMessage.by_user_id(:key => self.id).all + + messages = [] + user_messages.each do |um| + messages << Message.find(um.message.id) + end + messages + + end + # DEPRECATED # # Please set the key on the identity directly -- cgit v1.2.3 From 7f12c795207ac818bffac42aa581bf1165f9e424 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 24 Dec 2013 13:27:22 -0800 Subject: Catching some corner cases & new tests. --- users/app/controllers/v1/messages_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index fa98042..d49b161 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -10,14 +10,13 @@ module V1 render json: (user ? user.messages : [] ) end - # routes ensure this is only for PUT def mark_read user_message = UserMessage.find_by_user_id_and_message_id([params[:user_id], params[:message_id]]) - user_message.seen = true + user_message.seen = true if user_message # TODO what to return? - if user_message.save + if user_message and user_message.save render json: true else render json: false -- cgit v1.2.3 From fac34e1fb21d9310227c4cfc28c3ef03806ba465 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 26 Dec 2013 12:37:26 -0800 Subject: Very very rough start to having messages for payment automatically created. --- users/app/models/user.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'users/app') diff --git a/users/app/models/user.rb b/users/app/models/user.rb index fe3a127..28adc54 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -122,6 +122,26 @@ class User < CouchRest::Model::Base ServiceLevel.new({id: code}) end + def one_month_warning_to_pay + # get all users who are not customers with active subscription and have existed for exactly a month (take account of months having difft amount of days. Maybe jsut those who signed up 30 days ago?) + #users_to_warn = User.find_by_created_at(Time.now-1.month).all #NO, this will require time to be right + #users_1_month_old = User.by_created_at.startkey(Time.now-1.month-1.day).endkey(Time.now-1.month).al + users_30_days_old = User.by_created_at.startkey(Time.now-31.days).endkey(Time.now-30.days).all + # TODO, now, limit users to those who do not have a braintree customer, or have a braintree customer without an active subscription. This might have to happen when we are looping through anyway. + #users_to_warn = + + # TODO: only create message if any messages are going to be created. + # create a message for today's date + message = Message.new(:text => t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m"))) + message.save + + # for each such user, create a user message for that user and the message + users_to_warn.each do |user_to_warn| + user_message = UserMessage.new(:message_id => message.id, :user_id => user_to_warn.id) + user_message.save + end + end + protected ## -- cgit v1.2.3 From 7d1a25c2477b9607475f6b4c56f94d392c46950a Mon Sep 17 00:00:00 2001 From: jessib Date: Mon, 30 Dec 2013 11:41:51 -0800 Subject: Not actually how we want to do this, but at least finish outlined part, that will later be replaced. --- users/app/models/user.rb | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'users/app') diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 28adc54..bf48185 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -123,22 +123,30 @@ class User < CouchRest::Model::Base end def one_month_warning_to_pay - # get all users who are not customers with active subscription and have existed for exactly a month (take account of months having difft amount of days. Maybe jsut those who signed up 30 days ago?) + # get all users who are not customers with active subscription and have existed for exactly a month (take account of months having difft amount of days. Maybe just those who signed up 30 days ago?) #users_to_warn = User.find_by_created_at(Time.now-1.month).all #NO, this will require time to be right #users_1_month_old = User.by_created_at.startkey(Time.now-1.month-1.day).endkey(Time.now-1.month).al users_30_days_old = User.by_created_at.startkey(Time.now-31.days).endkey(Time.now-30.days).all - # TODO, now, limit users to those who do not have a braintree customer, or have a braintree customer without an active subscription. This might have to happen when we are looping through anyway. - #users_to_warn = - - # TODO: only create message if any messages are going to be created. - # create a message for today's date - message = Message.new(:text => t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m"))) - message.save - - # for each such user, create a user message for that user and the message - users_to_warn.each do |user_to_warn| - user_message = UserMessage.new(:message_id => message.id, :user_id => user_to_warn.id) - user_message.save + # TODO, above really is quite problematic, in that if the cron job fails to run on 1 day, say, the warning will not get created. + + users_30_days_old.each do |user| + + # create a user message for each user that does not has a braintree customer, or + # has a braintree customer w/out an active subscription. + unless ((customer = Customer.find_by_user(user.id)) && customer.subscriptions) + + if !@message + # create a message for today's date + # only want to create once, and only if it will be used. + @message = Message.new(:text => t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m"))) + @message.save + end + + user_message = UserMessage.new(:message_id => @message.id, :user_id => user.id) + # is following preferred?? + # user_message = UserMessage.new(:message => @message, :user => user) + user_message.save + end end end -- cgit v1.2.3 From 16b28882aa7659fb89e1661ed8af0c0db72642c8 Mon Sep 17 00:00:00 2001 From: jessib Date: Mon, 30 Dec 2013 15:22:44 -0800 Subject: Change structure to be more no-sql-y, rather than relational. --- users/app/controllers/v1/messages_controller.rb | 12 ++++++++++++ users/app/models/user.rb | 13 +++++++++++++ users/app/models/user_message.rb | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index d49b161..18f9f46 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -12,6 +12,7 @@ module V1 # routes ensure this is only for PUT def mark_read +=begin user_message = UserMessage.find_by_user_id_and_message_id([params[:user_id], params[:message_id]]) user_message.seen = true if user_message @@ -22,6 +23,17 @@ module V1 render json: false end end +=end + if (user = User.find(params[:user_id])) && Message.find(params[:message_id]) + user.message_ids_seen << params[:message_id] if !user.message_ids_seen.include?(params[:message_id]) #is it quicker to instead run uniq after adding? + user.message_ids_to_see.delete(params[:message_id]) + user.save + render json: true + return + else + render json: false + end + end end end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index fe3a127..fc63ae9 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -13,6 +13,9 @@ class User < CouchRest::Model::Base property :desired_service_level_code, Integer, :accessible => true property :effective_service_level_code, Integer, :accessible => true + property :message_ids_to_see, [String] + property :message_ids_seen, [String] + before_save :update_effective_service_level validates :login, :password_salt, :password_verifier, @@ -74,6 +77,7 @@ class User < CouchRest::Model::Base def messages(unseen = true) +=begin user_messages = unseen ? UserMessage.by_user_id_and_seen(:key => [self.id, false]).all : UserMessage.by_user_id(:key => self.id).all messages = [] @@ -81,6 +85,15 @@ class User < CouchRest::Model::Base messages << Message.find(um.message.id) end messages +=end + + message_ids = unseen ? self.message_ids_to_see : self.message_ids_to_see + self.message_ids_seen # TODO check unique? + + messages = [] + message_ids.each do |message_id| + messages << Message.find(message_id) + end + messages end diff --git a/users/app/models/user_message.rb b/users/app/models/user_message.rb index 37aae0b..51ca46c 100644 --- a/users/app/models/user_message.rb +++ b/users/app/models/user_message.rb @@ -1,4 +1,5 @@ -class UserMessage < CouchRest::Model::Base +# TODO WOULD NOT USE anymore, in proposed alternate, so delete file. +class XXXXUserMessage < CouchRest::Model::Base use_database :user_messages belongs_to :user -- cgit v1.2.3 From 4dae5eaa1bdb211d9d3ff29d5a9e9a86424e9748 Mon Sep 17 00:00:00 2001 From: jessib Date: Mon, 30 Dec 2013 16:22:38 -0800 Subject: Fixes to initial go at job to send one month warnings. --- ...by_created_at_and_one_month_warning_not_sent.js | 5 +++++ users/app/models/user.rb | 23 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 users/app/designs/user/by_created_at_and_one_month_warning_not_sent.js (limited to 'users/app') diff --git a/users/app/designs/user/by_created_at_and_one_month_warning_not_sent.js b/users/app/designs/user/by_created_at_and_one_month_warning_not_sent.js new file mode 100644 index 0000000..53a95de --- /dev/null +++ b/users/app/designs/user/by_created_at_and_one_month_warning_not_sent.js @@ -0,0 +1,5 @@ +function (doc) { + if ((doc['type'] == 'User') && (doc['created_at'] != null) && (doc['one_month_warning_sent'] == null)) { + emit(doc['created_at'], 1); + } +} diff --git a/users/app/models/user.rb b/users/app/models/user.rb index d9b03ec..30b9ee7 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -15,6 +15,7 @@ class User < CouchRest::Model::Base property :message_ids_to_see, [String] property :message_ids_seen, [String] + property :one_month_warning_sent, TrueClass before_save :update_effective_service_level @@ -135,7 +136,10 @@ class User < CouchRest::Model::Base ServiceLevel.new({id: code}) end - def one_month_warning_to_pay + + def self.send_one_month_warnings # class not instance method + +=begin # get all users who are not customers with active subscription and have existed for exactly a month (take account of months having difft amount of days. Maybe just those who signed up 30 days ago?) #users_to_warn = User.find_by_created_at(Time.now-1.month).all #NO, this will require time to be right #users_1_month_old = User.by_created_at.startkey(Time.now-1.month-1.day).endkey(Time.now-1.month).al @@ -161,6 +165,23 @@ class User < CouchRest::Model::Base user_message.save end end +=end + + #to determine warnings to send, need to get all users where one_month_warning_sent is not set, and where it was created greater than or equal to 1 month ago. this will likely be custom js view/design + users_to_warn = User.by_created_at_and_one_month_warning_not_sent.endkey(Time.now-1.month) + users_to_warn.each do |user| + if !@message + # create a message for today's date + # only want to create once, and only if it will be used. + @message = Message.new(:text => t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m"))) + @message.save + end + + user.message_ids_to_see << @message.id + user.one_month_warning_sent = true + user.save #?? + end + end protected -- cgit v1.2.3 From f9c96f8844205afe3c310b5b914752068728d38f Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 31 Dec 2013 11:48:18 -0800 Subject: Cleanup of code for messages API and cron job for 1 month payment warning. Authentication still remaining piece. --- users/app/controllers/v1/messages_controller.rb | 15 ++------ users/app/models/user.rb | 47 +++---------------------- 2 files changed, 8 insertions(+), 54 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index 18f9f46..42a88f7 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -12,20 +12,11 @@ module V1 # routes ensure this is only for PUT def mark_read -=begin - user_message = UserMessage.find_by_user_id_and_message_id([params[:user_id], params[:message_id]]) - user_message.seen = true if user_message - # TODO what to return? - if user_message and user_message.save - render json: true - else - render json: false - end - end -=end + # make sure user and message exist if (user = User.find(params[:user_id])) && Message.find(params[:message_id]) - user.message_ids_seen << params[:message_id] if !user.message_ids_seen.include?(params[:message_id]) #is it quicker to instead run uniq after adding? + + user.message_ids_seen << params[:message_id] if !user.message_ids_seen.include?(params[:message_id]) #TODO: is it quicker to instead call uniq! after adding? user.message_ids_to_see.delete(params[:message_id]) user.save render json: true diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 30b9ee7..6e445be 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -78,16 +78,6 @@ class User < CouchRest::Model::Base def messages(unseen = true) -=begin - user_messages = unseen ? UserMessage.by_user_id_and_seen(:key => [self.id, false]).all : UserMessage.by_user_id(:key => self.id).all - - messages = [] - user_messages.each do |um| - messages << Message.find(um.message.id) - end - messages -=end - message_ids = unseen ? self.message_ids_to_see : self.message_ids_to_see + self.message_ids_seen # TODO check unique? messages = [] @@ -137,49 +127,22 @@ class User < CouchRest::Model::Base end - def self.send_one_month_warnings # class not instance method - -=begin - # get all users who are not customers with active subscription and have existed for exactly a month (take account of months having difft amount of days. Maybe just those who signed up 30 days ago?) - #users_to_warn = User.find_by_created_at(Time.now-1.month).all #NO, this will require time to be right - #users_1_month_old = User.by_created_at.startkey(Time.now-1.month-1.day).endkey(Time.now-1.month).al - users_30_days_old = User.by_created_at.startkey(Time.now-31.days).endkey(Time.now-30.days).all - # TODO, above really is quite problematic, in that if the cron job fails to run on 1 day, say, the warning will not get created. - - users_30_days_old.each do |user| - - # create a user message for each user that does not has a braintree customer, or - # has a braintree customer w/out an active subscription. - unless ((customer = Customer.find_by_user(user.id)) && customer.subscriptions) - - if !@message - # create a message for today's date - # only want to create once, and only if it will be used. - @message = Message.new(:text => t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m"))) - @message.save - end - - user_message = UserMessage.new(:message_id => @message.id, :user_id => user.id) - # is following preferred?? - # user_message = UserMessage.new(:message => @message, :user => user) - user_message.save - end - end -=end + def self.send_one_month_warnings - #to determine warnings to send, need to get all users where one_month_warning_sent is not set, and where it was created greater than or equal to 1 month ago. this will likely be custom js view/design + # To determine warnings to send, need to get all users where one_month_warning_sent is not set, and where it was created greater than or equal to 1 month ago. + # TODO: might want to further limit to enabled accounts, and, based on provider's service level configuration, for particular service levels. users_to_warn = User.by_created_at_and_one_month_warning_not_sent.endkey(Time.now-1.month) users_to_warn.each do |user| if !@message # create a message for today's date # only want to create once, and only if it will be used. - @message = Message.new(:text => t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m"))) + @message = Message.new(:text => I18n.t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m"))) @message.save end user.message_ids_to_see << @message.id user.one_month_warning_sent = true - user.save #?? + user.save end end -- cgit v1.2.3 From fe3e374daa274a38723da52d929805b80f7ef383 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 31 Dec 2013 11:50:34 -0800 Subject: Removing join-model we are no longer using. --- users/app/models/user_message.rb | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 users/app/models/user_message.rb (limited to 'users/app') diff --git a/users/app/models/user_message.rb b/users/app/models/user_message.rb deleted file mode 100644 index 51ca46c..0000000 --- a/users/app/models/user_message.rb +++ /dev/null @@ -1,26 +0,0 @@ -# TODO WOULD NOT USE anymore, in proposed alternate, so delete file. -class XXXXUserMessage < CouchRest::Model::Base - - use_database :user_messages - belongs_to :user - belongs_to :message - - validates :user_id, presence: true - validates :message_id, presence: true - - # should not have multiple rows connecting one user to particular message: - validates_uniqueness_of :user_id, :scope => [:message_id] - - property :seen, TrueClass, :default => false - - design do - view :by_user_id - view :by_message_id - view :by_user_id_and_seen - view :by_user_id_and_message_id - own_path = Pathname.new(File.dirname(__FILE__)) - load_views(own_path.join('..', 'designs', 'user_message')) - - end - -end -- cgit v1.2.3 From 47d9b62913789358aefe769de6b7e33da8547891 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 31 Dec 2013 12:16:43 -0800 Subject: Add authentication to API, but not sure it is best way. --- users/app/controllers/v1/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index 42a88f7..b58dfe9 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -1,7 +1,7 @@ module V1 class MessagesController < ApplicationController - # TODO need to add authentication + before_filter :authorize_admin # not sure this is best way respond_to :json # for now, will not pass unseen, so unseen will always be true -- cgit v1.2.3 From c7e66852324714a166dd35dc3d5873a0053dcb9b Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 7 Jan 2014 12:57:01 -0800 Subject: Some refactoring, to simplify user model, optimize, and allow messages to be sorted by date (although are not now.) Also, rather than use whenever gem, will have cron job created to call task. --- users/app/controllers/v1/messages_controller.rb | 29 ++++++++++------------ users/app/designs/message/by_user_ids_to_show.js | 7 ++++++ .../message/by_user_ids_to_show_and_created_at.js | 8 ++++++ users/app/models/message.rb | 4 +++ users/app/models/user.rb | 14 +++++------ 5 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 users/app/designs/message/by_user_ids_to_show.js create mode 100644 users/app/designs/message/by_user_ids_to_show_and_created_at.js (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index b58dfe9..371b83e 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -1,30 +1,27 @@ module V1 class MessagesController < ApplicationController - before_filter :authorize_admin # not sure this is best way + skip_before_filter :verify_authenticity_token + before_filter :authorize + respond_to :json - # for now, will not pass unseen, so unseen will always be true - def user_messages(unseen = true) - user = User.find(params[:user_id]) - render json: (user ? user.messages : [] ) + def index + render json: (current_user ? current_user.messages : [] ) end - # routes ensure this is only for PUT - def mark_read - - # make sure user and message exist - if (user = User.find(params[:user_id])) && Message.find(params[:message_id]) - - user.message_ids_seen << params[:message_id] if !user.message_ids_seen.include?(params[:message_id]) #TODO: is it quicker to instead call uniq! after adding? - user.message_ids_to_see.delete(params[:message_id]) - user.save + def update + message = Message.find(params[:id]) + if (message and current_user) + message.user_ids_to_show.delete(current_user.id) + # is it necessary to keep track of what users have already seen it?: + message.user_ids_have_shown << current_user.id if !message.user_ids_have_shown.include?(current_user.id) #TODO: is it quicker to instead call uniq! after adding? + message.save render json: true - return else render json: false end - end + end end diff --git a/users/app/designs/message/by_user_ids_to_show.js b/users/app/designs/message/by_user_ids_to_show.js new file mode 100644 index 0000000..95ccd0d --- /dev/null +++ b/users/app/designs/message/by_user_ids_to_show.js @@ -0,0 +1,7 @@ +function (doc) { + if (doc.type === 'Message' && doc.user_ids_to_show && Array.isArray(doc.user_ids_to_show)) { + doc.user_ids_to_show.forEach(function (userIdsToShow) { + emit(userIdsToShow, 1); + }); + } +} \ No newline at end of file diff --git a/users/app/designs/message/by_user_ids_to_show_and_created_at.js b/users/app/designs/message/by_user_ids_to_show_and_created_at.js new file mode 100644 index 0000000..7bd7c2c --- /dev/null +++ b/users/app/designs/message/by_user_ids_to_show_and_created_at.js @@ -0,0 +1,8 @@ +// not using at moment +function (doc) { + if (doc.type === 'Message' && doc.user_ids_to_show && Array.isArray(doc.user_ids_to_show)) { + doc.user_ids_to_show.forEach(function (userIdsToShow) { + emit([userIdsToShow, doc.created_at], 1); + }); + } +} \ No newline at end of file diff --git a/users/app/models/message.rb b/users/app/models/message.rb index 38fa71e..16a19f4 100644 --- a/users/app/models/message.rb +++ b/users/app/models/message.rb @@ -3,8 +3,12 @@ class Message < CouchRest::Model::Base use_database :messages property :text, String + property :user_ids_to_show, [String] + property :user_ids_have_shown, [String] # is this necessary to store? design do + own_path = Pathname.new(File.dirname(__FILE__)) + load_views(own_path.join('..', 'designs', 'message')) end end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 6e445be..71e57f3 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -13,8 +13,6 @@ class User < CouchRest::Model::Base property :desired_service_level_code, Integer, :accessible => true property :effective_service_level_code, Integer, :accessible => true - property :message_ids_to_see, [String] - property :message_ids_seen, [String] property :one_month_warning_sent, TrueClass before_save :update_effective_service_level @@ -77,12 +75,11 @@ class User < CouchRest::Model::Base end def messages(unseen = true) - - message_ids = unseen ? self.message_ids_to_see : self.message_ids_to_see + self.message_ids_seen # TODO check unique? - + #TODO for now this only shows unseen messages. Will we ever want seen ones? Is it necessary to store? + #Message.by_user_ids_to_show.key(self.id).all # we don't want to emit all the userids associated with a message, so looping through to only emit text and id. messages = [] - message_ids.each do |message_id| - messages << Message.find(message_id) + Message.by_user_ids_to_show.key(self.id).each do |message| + messages << [message.id, message.text] end messages @@ -140,7 +137,8 @@ class User < CouchRest::Model::Base @message.save end - user.message_ids_to_see << @message.id + @message.user_ids_to_show << user.id + @message.save user.one_month_warning_sent = true user.save end -- cgit v1.2.3 From 6c478c5a1634b5da9d269c938f67d2ac4d8f03df Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 9 Jan 2014 12:18:37 -0800 Subject: Some more cleanup, but still want to make sure by_user_ids_to_show_and_created_at view is right before issuing pull request. --- users/app/controllers/v1/messages_controller.rb | 5 +++-- users/app/designs/message/by_user_ids_to_show_and_created_at.js | 2 +- users/app/models/message.rb | 2 ++ users/app/models/user.rb | 9 +++------ 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index 371b83e..1b994ca 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -14,8 +14,9 @@ module V1 message = Message.find(params[:id]) if (message and current_user) message.user_ids_to_show.delete(current_user.id) - # is it necessary to keep track of what users have already seen it?: - message.user_ids_have_shown << current_user.id if !message.user_ids_have_shown.include?(current_user.id) #TODO: is it quicker to instead call uniq! after adding? + # is it necessary to keep track of what users have already seen it? + message.user_ids_have_shown << current_user.id if !message.user_ids_have_shown.include?(current_user.id) + # TODO: is it quicker to call uniq! after adding rather than check if it is already included? message.save render json: true else diff --git a/users/app/designs/message/by_user_ids_to_show_and_created_at.js b/users/app/designs/message/by_user_ids_to_show_and_created_at.js index 7bd7c2c..bb6412b 100644 --- a/users/app/designs/message/by_user_ids_to_show_and_created_at.js +++ b/users/app/designs/message/by_user_ids_to_show_and_created_at.js @@ -2,7 +2,7 @@ function (doc) { if (doc.type === 'Message' && doc.user_ids_to_show && Array.isArray(doc.user_ids_to_show)) { doc.user_ids_to_show.forEach(function (userIdsToShow) { - emit([userIdsToShow, doc.created_at], 1); + emit([userIdsToShow, doc.created_at], 1); }); } } \ No newline at end of file diff --git a/users/app/models/message.rb b/users/app/models/message.rb index 16a19f4..d9ccee8 100644 --- a/users/app/models/message.rb +++ b/users/app/models/message.rb @@ -6,6 +6,8 @@ class Message < CouchRest::Model::Base property :user_ids_to_show, [String] property :user_ids_have_shown, [String] # is this necessary to store? + timestamps! + design do own_path = Pathname.new(File.dirname(__FILE__)) load_views(own_path.join('..', 'designs', 'message')) diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 71e57f3..44237ff 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -76,12 +76,9 @@ class User < CouchRest::Model::Base def messages(unseen = true) #TODO for now this only shows unseen messages. Will we ever want seen ones? Is it necessary to store? - #Message.by_user_ids_to_show.key(self.id).all # we don't want to emit all the userids associated with a message, so looping through to only emit text and id. - messages = [] - Message.by_user_ids_to_show.key(self.id).each do |message| - messages << [message.id, message.text] - end - messages + + # we don't want to emit all the userids associated with a message, so only emit id and text. + Message.by_user_ids_to_show.key(self.id).map { |message| [message.id, message.text] } end -- cgit v1.2.3 From a19d01313ac534bdbbd8381593f887f1f77c94d5 Mon Sep 17 00:00:00 2001 From: jessib Date: Mon, 13 Jan 2014 11:28:14 -0800 Subject: Comment for how to call view that we aren't now using. --- users/app/designs/message/by_user_ids_to_show_and_created_at.js | 1 + 1 file changed, 1 insertion(+) (limited to 'users/app') diff --git a/users/app/designs/message/by_user_ids_to_show_and_created_at.js b/users/app/designs/message/by_user_ids_to_show_and_created_at.js index bb6412b..18969b8 100644 --- a/users/app/designs/message/by_user_ids_to_show_and_created_at.js +++ b/users/app/designs/message/by_user_ids_to_show_and_created_at.js @@ -1,4 +1,5 @@ // not using at moment +// call with something like Message.by_user_ids_to_show_and_created_at.startkey([user_id, start_date]).endkey([user_id,end_date]) function (doc) { if (doc.type === 'Message' && doc.user_ids_to_show && Array.isArray(doc.user_ids_to_show)) { doc.user_ids_to_show.forEach(function (userIdsToShow) { -- cgit v1.2.3 From 3bfbf0ad20bb5b8e4689fda287cd47738571d10d Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 21 Jan 2014 11:26:19 -0800 Subject: Small optimization to saving message when sending one month warnings. --- users/app/models/user.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'users/app') diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 44237ff..c297ac8 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -126,19 +126,23 @@ class User < CouchRest::Model::Base # To determine warnings to send, need to get all users where one_month_warning_sent is not set, and where it was created greater than or equal to 1 month ago. # TODO: might want to further limit to enabled accounts, and, based on provider's service level configuration, for particular service levels. users_to_warn = User.by_created_at_and_one_month_warning_not_sent.endkey(Time.now-1.month) + users_to_warn.each do |user| + # instead of loop could use something like: + # message.user_ids_to_show = users_to_warn.map(&:id) + # but would still need to loop through users to store one_month_warning_sent + if !@message # create a message for today's date # only want to create once, and only if it will be used. @message = Message.new(:text => I18n.t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m"))) - @message.save end @message.user_ids_to_show << user.id - @message.save user.one_month_warning_sent = true user.save end + @message.save if @message end -- cgit v1.2.3 From bd867c51c4d9e3d4c6b4c55d326eb9b13b89288b Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Feb 2014 14:23:38 +0100 Subject: minor: move some logic from message controller into model --- users/app/controllers/v1/messages_controller.rb | 5 +---- users/app/models/message.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index 1b994ca..55292ff 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -13,10 +13,7 @@ module V1 def update message = Message.find(params[:id]) if (message and current_user) - message.user_ids_to_show.delete(current_user.id) - # is it necessary to keep track of what users have already seen it? - message.user_ids_have_shown << current_user.id if !message.user_ids_have_shown.include?(current_user.id) - # TODO: is it quicker to call uniq! after adding rather than check if it is already included? + message.mark_as_read_by(current_user) message.save render json: true else diff --git a/users/app/models/message.rb b/users/app/models/message.rb index d9ccee8..7c05e06 100644 --- a/users/app/models/message.rb +++ b/users/app/models/message.rb @@ -13,4 +13,18 @@ class Message < CouchRest::Model::Base load_views(own_path.join('..', 'designs', 'message')) end + def mark_as_read_by(user) + user_ids_to_show.delete(user.id) + # is it necessary to keep track of what users have already seen it? + user_ids_have_shown << user.id unless read_by?(user) + # TODO: is it quicker to call uniq! after adding rather than check if it is already included? + end + + def read_by?(user) + user_ids_have_shown.include?(user.id) + end + + def unread_by?(user) + user_ids_to_shown.include?(user.id) + end end -- cgit v1.2.3 From 2f00e2ec3c076e4910008904bc01e09df097944e Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Feb 2014 14:24:08 +0100 Subject: minor: rename var that holds a single user id to userId --- users/app/designs/message/by_user_ids_to_show.js | 6 +++--- users/app/designs/message/by_user_ids_to_show_and_created_at.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'users/app') diff --git a/users/app/designs/message/by_user_ids_to_show.js b/users/app/designs/message/by_user_ids_to_show.js index 95ccd0d..e33566b 100644 --- a/users/app/designs/message/by_user_ids_to_show.js +++ b/users/app/designs/message/by_user_ids_to_show.js @@ -1,7 +1,7 @@ function (doc) { if (doc.type === 'Message' && doc.user_ids_to_show && Array.isArray(doc.user_ids_to_show)) { - doc.user_ids_to_show.forEach(function (userIdsToShow) { - emit(userIdsToShow, 1); + doc.user_ids_to_show.forEach(function (userId) { + emit(userId, 1); }); } -} \ No newline at end of file +} diff --git a/users/app/designs/message/by_user_ids_to_show_and_created_at.js b/users/app/designs/message/by_user_ids_to_show_and_created_at.js index 18969b8..54e4604 100644 --- a/users/app/designs/message/by_user_ids_to_show_and_created_at.js +++ b/users/app/designs/message/by_user_ids_to_show_and_created_at.js @@ -2,8 +2,8 @@ // call with something like Message.by_user_ids_to_show_and_created_at.startkey([user_id, start_date]).endkey([user_id,end_date]) function (doc) { if (doc.type === 'Message' && doc.user_ids_to_show && Array.isArray(doc.user_ids_to_show)) { - doc.user_ids_to_show.forEach(function (userIdsToShow) { - emit([userIdsToShow, doc.created_at], 1); + doc.user_ids_to_show.forEach(function (userId) { + emit([userId, doc.created_at], 1); }); } -} \ No newline at end of file +} -- cgit v1.2.3 From e1243d02953b4012d6bb216efc9b0606809ab4bb Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 6 Feb 2014 09:47:37 +0100 Subject: minor: refactor token auth a bit --- .../controller_extension/token_authentication.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/controller_extension/token_authentication.rb b/users/app/controllers/controller_extension/token_authentication.rb index 530294a..cd5c074 100644 --- a/users/app/controllers/controller_extension/token_authentication.rb +++ b/users/app/controllers/controller_extension/token_authentication.rb @@ -1,11 +1,14 @@ module ControllerExtension::TokenAuthentication extend ActiveSupport::Concern - def token_authenticate - authenticate_with_http_token do |token_id, options| - @token = Token.find(token_id) + def token + @token ||= authenticate_with_http_token do |token_id, options| + Token.find(token_id) end - @token.authenticate if @token + end + + def token_authenticate + token.authenticate if token end def logout @@ -14,10 +17,7 @@ module ControllerExtension::TokenAuthentication end def clear_token - authenticate_with_http_token do |token_id, options| - @token = Token.find(token_id) - @token.destroy if @token - end + token.destroy if token end end -- cgit v1.2.3 From 3f9dc65636afb57fed441978dca4bf7d3209bd2d Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Feb 2014 14:38:56 +0100 Subject: rename authorize to require_login authorize_admin -> require_admin also add require_token which will ensure token has been used for auth. --- users/app/controllers/controller_extension/authentication.rb | 4 ++-- users/app/controllers/controller_extension/token_authentication.rb | 4 ++++ users/app/controllers/users_controller.rb | 4 ++-- users/app/controllers/v1/users_controller.rb | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/controller_extension/authentication.rb b/users/app/controllers/controller_extension/authentication.rb index d831fbe..e83d6b2 100644 --- a/users/app/controllers/controller_extension/authentication.rb +++ b/users/app/controllers/controller_extension/authentication.rb @@ -15,7 +15,7 @@ module ControllerExtension::Authentication !!current_user end - def authorize + def require_login access_denied unless logged_in? end @@ -38,7 +38,7 @@ module ControllerExtension::Authentication current_user && current_user.is_admin? end - def authorize_admin + def require_admin access_denied unless admin? end diff --git a/users/app/controllers/controller_extension/token_authentication.rb b/users/app/controllers/controller_extension/token_authentication.rb index cd5c074..ee24f73 100644 --- a/users/app/controllers/controller_extension/token_authentication.rb +++ b/users/app/controllers/controller_extension/token_authentication.rb @@ -11,6 +11,10 @@ module ControllerExtension::TokenAuthentication token.authenticate if token end + def require_token + access_denied unless token + end + def logout super clear_token diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index a5461cd..6b32d49 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -4,9 +4,9 @@ class UsersController < UsersBaseController - before_filter :authorize, :only => [:show, :edit, :update, :destroy] + before_filter :require_login, :except => [:new] + before_filter :require_admin, :only => [:index, :deactivate, :enable] before_filter :fetch_user, :only => [:show, :edit, :update, :destroy, :deactivate, :enable] - before_filter :authorize_admin, :only => [:index, :deactivate, :enable] respond_to :html diff --git a/users/app/controllers/v1/users_controller.rb b/users/app/controllers/v1/users_controller.rb index 0903888..a16c6e9 100644 --- a/users/app/controllers/v1/users_controller.rb +++ b/users/app/controllers/v1/users_controller.rb @@ -3,8 +3,8 @@ module V1 skip_before_filter :verify_authenticity_token before_filter :fetch_user, :only => [:update] - before_filter :authorize, :only => [:update] - before_filter :authorize_admin, :only => [:index] + before_filter :require_login, :only => [:update, :index] + before_filter :require_admin, :only => [:index] respond_to :json -- cgit v1.2.3 From cbd757cf151cd61bfdd5637d09f43e4831fec3bb Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 8 Feb 2014 16:15:46 +0100 Subject: require token when updating user via API --- users/app/controllers/v1/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/users_controller.rb b/users/app/controllers/v1/users_controller.rb index a16c6e9..8897d01 100644 --- a/users/app/controllers/v1/users_controller.rb +++ b/users/app/controllers/v1/users_controller.rb @@ -3,8 +3,8 @@ module V1 skip_before_filter :verify_authenticity_token before_filter :fetch_user, :only => [:update] - before_filter :require_login, :only => [:update, :index] before_filter :require_admin, :only => [:index] + before_filter :require_token, :only => [:update] respond_to :json -- cgit v1.2.3 From c8fcd0d26c3ad5c1c3cfbaf6b57239f907925ed6 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 8 Feb 2014 16:20:37 +0100 Subject: require token when logging out via API --- users/app/controllers/v1/sessions_controller.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'users/app') diff --git a/users/app/controllers/v1/sessions_controller.rb b/users/app/controllers/v1/sessions_controller.rb index eb6c322..eae3a1e 100644 --- a/users/app/controllers/v1/sessions_controller.rb +++ b/users/app/controllers/v1/sessions_controller.rb @@ -2,6 +2,7 @@ module V1 class SessionsController < ApplicationController skip_before_filter :verify_authenticity_token + before_filter :require_token, only: :destroy def new @session = Session.new -- cgit v1.2.3 From 3a478804aa48b08fbeded5144677744c427c112f Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Feb 2014 14:29:34 +0100 Subject: require token in messages controller --- users/app/controllers/v1/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'users/app') diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb index 1b994ca..90986e2 100644 --- a/users/app/controllers/v1/messages_controller.rb +++ b/users/app/controllers/v1/messages_controller.rb @@ -2,7 +2,7 @@ module V1 class MessagesController < ApplicationController skip_before_filter :verify_authenticity_token - before_filter :authorize + before_filter :require_token respond_to :json -- cgit v1.2.3 From b6c8279a39f933257be11fc29f5b7d59efff743f Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Feb 2014 14:34:17 +0100 Subject: require_token now checks for token and login --- users/app/controllers/controller_extension/token_authentication.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/controller_extension/token_authentication.rb b/users/app/controllers/controller_extension/token_authentication.rb index ee24f73..6e0a6ce 100644 --- a/users/app/controllers/controller_extension/token_authentication.rb +++ b/users/app/controllers/controller_extension/token_authentication.rb @@ -8,11 +8,11 @@ module ControllerExtension::TokenAuthentication end def token_authenticate - token.authenticate if token + @token_authenticated ||= token.authenticate if token end def require_token - access_denied unless token + access_denied unless token_authenticate end def logout -- cgit v1.2.3 From e3577906891f9ab0edd987544e3432f354bc1721 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Feb 2014 19:41:02 +0100 Subject: fix unread_by? to check user_ids_to_show, remove TODO uniq! is probably not any faster than just checking include? --- users/app/models/message.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'users/app') diff --git a/users/app/models/message.rb b/users/app/models/message.rb index 7c05e06..424f094 100644 --- a/users/app/models/message.rb +++ b/users/app/models/message.rb @@ -17,7 +17,6 @@ class Message < CouchRest::Model::Base user_ids_to_show.delete(user.id) # is it necessary to keep track of what users have already seen it? user_ids_have_shown << user.id unless read_by?(user) - # TODO: is it quicker to call uniq! after adding rather than check if it is already included? end def read_by?(user) @@ -25,6 +24,6 @@ class Message < CouchRest::Model::Base end def unread_by?(user) - user_ids_to_shown.include?(user.id) + user_ids_to_show.include?(user.id) end end -- cgit v1.2.3 From 85aabe832eb3eec10a29054ef5575618686eef33 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 4 Apr 2014 11:48:24 +0200 Subject: 5382 - prevent crash when destroying tokens An expired token was removed (probably by automatic cleanup) while processing it. So the webapp crashed due to a couch 404. We're preventing that by rescueing from a 404 on Token.delete by default. --- users/app/models/token.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'users/app') diff --git a/users/app/models/token.rb b/users/app/models/token.rb index 001eb40..4856c31 100644 --- a/users/app/models/token.rb +++ b/users/app/models/token.rb @@ -40,6 +40,14 @@ class Token < CouchRest::Model::Base end end + # Tokens can be cleaned up in different ways. + # So let's make sure we don't crash if they disappeared + def destroy_with_rescue + destroy_without_rescue + rescue RestClient::ResourceNotFound + end + alias_method_chain :destroy, :rescue + def touch self.last_seen_at = Time.now save -- cgit v1.2.3 From aeb5d8cf8dc6329906f14bf4595a229e002691c1 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 4 Apr 2014 15:40:22 +0200 Subject: redirect home when logged in visits /signup (#5446) --- users/app/controllers/controller_extension/authentication.rb | 7 +++++++ users/app/controllers/sessions_controller.rb | 3 ++- users/app/controllers/users_controller.rb | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'users/app') diff --git a/users/app/controllers/controller_extension/authentication.rb b/users/app/controllers/controller_extension/authentication.rb index e83d6b2..03d3989 100644 --- a/users/app/controllers/controller_extension/authentication.rb +++ b/users/app/controllers/controller_extension/authentication.rb @@ -19,6 +19,13 @@ module ControllerExtension::Authentication access_denied unless logged_in? end + # some actions only make sense if you are not logged in yet. + # (login, signup). If a user tries to perform these they will + # be redirected to their dashboard. + def redirect_if_logged_in + redirect_to home_url if logged_in? + end + def access_denied respond_to do |format| format.html do diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb index 0195f30..8919a4d 100644 --- a/users/app/controllers/sessions_controller.rb +++ b/users/app/controllers/sessions_controller.rb @@ -1,7 +1,8 @@ class SessionsController < ApplicationController + before_filter :redirect_if_logged_in, :only => [:new] + def new - redirect_to home_url if logged_in? @session = Session.new if authentication_errors @errors = authentication_errors diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 6b32d49..c8e09b6 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -5,6 +5,7 @@ class UsersController < UsersBaseController before_filter :require_login, :except => [:new] + before_filter :redirect_if_logged_in, :only => [:new] before_filter :require_admin, :only => [:index, :deactivate, :enable] before_filter :fetch_user, :only => [:show, :edit, :update, :destroy, :deactivate, :enable] -- cgit v1.2.3 From b6d14dc19dd350a807826e3e097738a36613e083 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 8 Apr 2014 11:49:14 +0200 Subject: moving users: app and test files --- users/app/assets/images/leap_web_users/.gitkeep | 0 .../app/assets/javascripts/leap_web_users/.gitkeep | 0 users/app/assets/javascripts/srp | 1 - users/app/assets/javascripts/users.js | 132 --------------- .../app/assets/stylesheets/leap_web_users/.gitkeep | 0 users/app/controllers/.gitkeep | 0 .../app/controllers/account_settings_controller.rb | 0 .../controller_extension/authentication.rb | 75 --------- .../controller_extension/token_authentication.rb | 27 ---- users/app/controllers/keys_controller.rb | 18 --- users/app/controllers/sessions_controller.rb | 28 ---- users/app/controllers/users_base_controller.rb | 18 --- users/app/controllers/users_controller.rb | 69 -------- users/app/controllers/v1/messages_controller.rb | 25 --- users/app/controllers/v1/sessions_controller.rb | 45 ------ users/app/controllers/v1/users_controller.rb | 32 ---- users/app/controllers/webfinger_controller.rb | 19 --- users/app/designs/message/by_user_ids_to_show.js | 7 - .../message/by_user_ids_to_show_and_created_at.js | 9 -- ...by_created_at_and_one_month_warning_not_sent.js | 5 - users/app/helpers/.gitkeep | 0 users/app/helpers/email_aliases_helper.rb | 11 -- users/app/helpers/sessions_helper.rb | 2 - users/app/helpers/users_helper.rb | 14 -- users/app/mailers/.gitkeep | 0 users/app/models/.gitkeep | 0 users/app/models/account.rb | 68 -------- users/app/models/email.rb | 26 --- users/app/models/identity.rb | 136 ---------------- users/app/models/local_email.rb | 68 -------- users/app/models/login_format_validation.rb | 21 --- users/app/models/message.rb | 29 ---- users/app/models/pgp_key.rb | 48 ------ users/app/models/service_level.rb | 19 --- users/app/models/session.rb | 32 ---- users/app/models/token.rb | 69 -------- users/app/models/unauthenticated_user.rb | 6 - users/app/models/user.rb | 179 --------------------- users/app/views/.gitkeep | 0 users/app/views/emails/_email.html.haml | 6 - users/app/views/sessions/new.html.haml | 10 -- users/app/views/sessions/new.json.erb | 3 - users/app/views/users/_change_password.html.haml | 21 --- users/app/views/users/_change_pgp_key.html.haml | 13 -- .../views/users/_change_service_level.html.haml | 18 --- users/app/views/users/_destroy_account.html.haml | 27 ---- users/app/views/users/_edit.html.haml | 14 -- users/app/views/users/_user.html.haml | 4 - users/app/views/users/_warnings.html.haml | 12 -- users/app/views/users/edit.html.haml | 1 - users/app/views/users/index.html.haml | 13 -- users/app/views/users/new.html.haml | 19 --- users/app/views/users/show.html.haml | 25 --- users/app/views/v1/sessions/new.json.erb | 3 - users/app/views/webfinger/host_meta.xml.erb | 11 -- users/app/views/webfinger/search.xml.erb | 7 - 56 files changed, 1445 deletions(-) delete mode 100644 users/app/assets/images/leap_web_users/.gitkeep delete mode 100644 users/app/assets/javascripts/leap_web_users/.gitkeep delete mode 160000 users/app/assets/javascripts/srp delete mode 100644 users/app/assets/javascripts/users.js delete mode 100644 users/app/assets/stylesheets/leap_web_users/.gitkeep delete mode 100644 users/app/controllers/.gitkeep delete mode 100644 users/app/controllers/account_settings_controller.rb delete mode 100644 users/app/controllers/controller_extension/authentication.rb delete mode 100644 users/app/controllers/controller_extension/token_authentication.rb delete mode 100644 users/app/controllers/keys_controller.rb delete mode 100644 users/app/controllers/sessions_controller.rb delete mode 100644 users/app/controllers/users_base_controller.rb delete mode 100644 users/app/controllers/users_controller.rb delete mode 100644 users/app/controllers/v1/messages_controller.rb delete mode 100644 users/app/controllers/v1/sessions_controller.rb delete mode 100644 users/app/controllers/v1/users_controller.rb delete mode 100644 users/app/controllers/webfinger_controller.rb delete mode 100644 users/app/designs/message/by_user_ids_to_show.js delete mode 100644 users/app/designs/message/by_user_ids_to_show_and_created_at.js delete mode 100644 users/app/designs/user/by_created_at_and_one_month_warning_not_sent.js delete mode 100644 users/app/helpers/.gitkeep delete mode 100644 users/app/helpers/email_aliases_helper.rb delete mode 100644 users/app/helpers/sessions_helper.rb delete mode 100644 users/app/helpers/users_helper.rb delete mode 100644 users/app/mailers/.gitkeep delete mode 100644 users/app/models/.gitkeep delete mode 100644 users/app/models/account.rb delete mode 100644 users/app/models/email.rb delete mode 100644 users/app/models/identity.rb delete mode 100644 users/app/models/local_email.rb delete mode 100644 users/app/models/login_format_validation.rb delete mode 100644 users/app/models/message.rb delete mode 100644 users/app/models/pgp_key.rb delete mode 100644 users/app/models/service_level.rb delete mode 100644 users/app/models/session.rb delete mode 100644 users/app/models/token.rb delete mode 100644 users/app/models/unauthenticated_user.rb delete mode 100644 users/app/models/user.rb delete mode 100644 users/app/views/.gitkeep delete mode 100644 users/app/views/emails/_email.html.haml delete mode 100644 users/app/views/sessions/new.html.haml delete mode 100644 users/app/views/sessions/new.json.erb delete mode 100644 users/app/views/users/_change_password.html.haml delete mode 100644 users/app/views/users/_change_pgp_key.html.haml delete mode 100644 users/app/views/users/_change_service_level.html.haml delete mode 100644 users/app/views/users/_destroy_account.html.haml delete mode 100644 users/app/views/users/_edit.html.haml delete mode 100644 users/app/views/users/_user.html.haml delete mode 100644 users/app/views/users/_warnings.html.haml delete mode 100644 users/app/views/users/edit.html.haml delete mode 100644 users/app/views/users/index.html.haml delete mode 100644 users/app/views/users/new.html.haml delete mode 100644 users/app/views/users/show.html.haml delete mode 100644 users/app/views/v1/sessions/new.json.erb delete mode 100644 users/app/views/webfinger/host_meta.xml.erb delete mode 100644 users/app/views/webfinger/search.xml.erb (limited to 'users/app') diff --git a/users/app/assets/images/leap_web_users/.gitkeep b/users/app/assets/images/leap_web_users/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/users/app/assets/javascripts/leap_web_users/.gitkeep b/users/app/assets/javascripts/leap_web_users/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/users/app/assets/javascripts/srp b/users/app/assets/javascripts/srp deleted file mode 160000 index 8f33d32..0000000 --- a/users/app/assets/javascripts/srp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8f33d32d40b1e21ae7fb9a92c78a275422af4217 diff --git a/users/app/assets/javascripts/users.js b/users/app/assets/javascripts/users.js deleted file mode 100644 index 8486756..0000000 --- a/users/app/assets/javascripts/users.js +++ /dev/null @@ -1,132 +0,0 @@ -(function() { - // - // LOCAL FUNCTIONS - // - - var poll_users, - prevent_default, - form_failed, - form_passed, - clear_errors, - update_user; - - prevent_default = function(event) { - return event.preventDefault(); - }; - - poll_users = function(query, process) { - return $.get("/1/users.json", { - query: query - }).done(process); - }; - - clear_errors = function() { - return $('#messages').empty(); - }; - - update_user = function(submitEvent) { - var form = submitEvent.target; - var token = form.dataset.token; - var url = form.action; - var req = $.ajax({ - url: url, - type: 'PUT', - headers: { Authorization: 'Token token="' + token + '"' }, - data: $(form).serialize() - }); - req.done( function() { - $(form).find('input[type="submit"]').button('reset'); - }); - }; - - markAsSubmitted = function(submitEvent) { - var form = submitEvent.target; - $(form).addClass('submitted') - // bootstrap loading state: - $(form).find('input[type="submit"]').button('loading'); - }; - - resetButtons = function(submitEvent) { - var form = $('form.submitted') - // bootstrap loading state: - $(form).find('input[type="submit"]').button('reset'); - $(form).removeClass('submitted') - }; - - // - // PUBLIC FUNCTIONS - // - - srp.session = new srp.Session(); - - srp.signedUp = function() { - return srp.login(); - }; - - srp.loggedIn = function() { - return window.location = '/'; - }; - - srp.updated = function() { - return window.location = '/users/' + srp.session.id(); - }; - - // - // if a json request returns an error, this function gets called and - // decorates the appropriate fields with the error messages. - // - srp.error = function(message) { - clear_errors(); - var errors = extractErrors(message); - displayErrors(errors); - resetButtons(); - } - - function extractErrors(message) { - if ($.isPlainObject(message) && message.errors) { - return message.errors; - } else { - return { - base: (message.error || JSON.stringify(message)) - }; - } - } - - function displayErrors(errors) { - for (var field in errors) { - var error = errors[field]; - if (field === 'base') { - alert_message(error); - } else { - displayFieldError(field, error); - } - } - } - - function displayFieldError(field, error) { - var element = $('form input[name$="[' + field + ']"]'); - if (element) { - element.trigger('element:validate:fail.ClientSideValidations', error).data('valid', false); - } - }; - - // - // INIT - // - - $(document).ready(function() { - $('form').submit(markAsSubmitted); - $('#new_user').submit(prevent_default); - $('#new_user').submit(srp.signup); - $('#new_session').submit(prevent_default); - $('#new_session').submit(srp.login); - $('#update_login_and_password').submit(prevent_default); - $('#update_login_and_password').submit(srp.update); - $('#update_pgp_key').submit(prevent_default); - $('#update_pgp_key').submit(update_user); - return $('#user-typeahead').typeahead({ - source: poll_users - }); - }); - -}).call(this); diff --git a/users/app/assets/stylesheets/leap_web_users/.gitkeep b/users/app/assets/stylesheets/leap_web_users/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/users/app/controllers/.gitkeep b/users/app/controllers/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/users/app/controllers/account_settings_controller.rb b/users/app/controllers/account_settings_controller.rb deleted file mode 100644 index e69de29..0000000 diff --git a/users/app/controllers/controller_extension/authentication.rb b/users/app/controllers/controller_extension/authentication.rb deleted file mode 100644 index 03d3989..0000000 --- a/users/app/controllers/controller_extension/authentication.rb +++ /dev/null @@ -1,75 +0,0 @@ -module ControllerExtension::Authentication - extend ActiveSupport::Concern - - private - - included do - helper_method :current_user, :logged_in?, :admin? - end - - def current_user - @current_user ||= token_authenticate || warden.user - end - - def logged_in? - !!current_user - end - - def require_login - access_denied unless logged_in? - end - - # some actions only make sense if you are not logged in yet. - # (login, signup). If a user tries to perform these they will - # be redirected to their dashboard. - def redirect_if_logged_in - redirect_to home_url if logged_in? - end - - def access_denied - respond_to do |format| - format.html do - if logged_in? - redirect_to home_url, :alert => t(:not_authorized) - else - redirect_to login_url, :alert => t(:not_authorized_login) - end - end - format.json do - render :json => {'error' => t(:not_authorized)}, status: :unprocessable_entity - end - end - end - - def admin? - current_user && current_user.is_admin? - end - - def require_admin - access_denied unless admin? - end - - def authentication_errors - return unless attempted_login? - errors = get_warden_errors - errors.inject({}) do |translated,err| - translated[err.first] = I18n.t(err.last) - translated - end - end - - def get_warden_errors - if strategy = warden.winning_strategy - message = strategy.message - # in case we get back the default message to fail! - message.respond_to?(:inject) ? message : { base: message } - else - { login: :all_strategies_failed } - end - end - - def attempted_login? - request.env['warden.options'] && - request.env['warden.options'][:attempted_path] - end -end diff --git a/users/app/controllers/controller_extension/token_authentication.rb b/users/app/controllers/controller_extension/token_authentication.rb deleted file mode 100644 index 6e0a6ce..0000000 --- a/users/app/controllers/controller_extension/token_authentication.rb +++ /dev/null @@ -1,27 +0,0 @@ -module ControllerExtension::TokenAuthentication - extend ActiveSupport::Concern - - def token - @token ||= authenticate_with_http_token do |token_id, options| - Token.find(token_id) - end - end - - def token_authenticate - @token_authenticated ||= token.authenticate if token - end - - def require_token - access_denied unless token_authenticate - end - - def logout - super - clear_token - end - - def clear_token - token.destroy if token - end -end - diff --git a/users/app/controllers/keys_controller.rb b/users/app/controllers/keys_controller.rb deleted file mode 100644 index fb28901..0000000 --- a/users/app/controllers/keys_controller.rb +++ /dev/null @@ -1,18 +0,0 @@ -class KeysController < ApplicationController - - # - # Render the user's key as plain text, without a layout. - # - # We will show blank page if user doesn't have key (which shouldn't generally occur) - # and a 404 error if user doesn't exist - # - def show - user = User.find_by_login(params[:login]) - if user - render text: user.public_key, content_type: 'text/text' - else - raise ActionController::RoutingError.new('Not Found') - end - end - -end diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb deleted file mode 100644 index 8919a4d..0000000 --- a/users/app/controllers/sessions_controller.rb +++ /dev/null @@ -1,28 +0,0 @@ -class SessionsController < ApplicationController - - before_filter :redirect_if_logged_in, :only => [:new] - - def new - @session = Session.new - if authentication_errors - @errors = authentication_errors - render :status => 422 - end - end - - def destroy - logout - redirect_to home_url - end - - # - # this is a bad hack, but user_url(user) is not available - # also, this doesn't work because the redirect happens as a PUT. no idea why. - # - #Warden::Manager.after_authentication do |user, auth, opts| - # response = Rack::Response.new - # response.redirect "/users/#{user.id}" - # throw :warden, response.finish - #end - -end diff --git a/users/app/controllers/users_base_controller.rb b/users/app/controllers/users_base_controller.rb deleted file mode 100644 index 9becf0d..0000000 --- a/users/app/controllers/users_base_controller.rb +++ /dev/null @@ -1,18 +0,0 @@ -# -# common base class for all user related controllers -# - -class UsersBaseController < ApplicationController - - protected - - def fetch_user - @user = User.find(params[:user_id] || params[:id]) - if !@user && admin? - redirect_to users_url, :alert => t(:no_such_thing, :thing => 'user') - elsif !admin? && @user != current_user - access_denied - end - end - -end diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb deleted file mode 100644 index c8e09b6..0000000 --- a/users/app/controllers/users_controller.rb +++ /dev/null @@ -1,69 +0,0 @@ -# -# This is an HTML-only controller. For the JSON-only controller, see v1/users_controller.rb -# - -class UsersController < UsersBaseController - - before_filter :require_login, :except => [:new] - before_filter :redirect_if_logged_in, :only => [:new] - before_filter :require_admin, :only => [:index, :deactivate, :enable] - before_filter :fetch_user, :only => [:show, :edit, :update, :destroy, :deactivate, :enable] - - respond_to :html - - def index - if params[:query] - if @user = User.find_by_login(params[:query]) - redirect_to @user - return - else - @users = User.by_login.startkey(params[:query]).endkey(params[:query].succ) - end - else - @users = User.by_created_at.descending - end - @users = @users.limit(100) - end - - def new - @user = User.new - end - - def show - end - - def edit - end - - ## added so updating service level works, but not sure we will actually want this. also not sure that this is place to prevent user from updating own effective service level, but here as placeholder: - def update - @user.update_attributes(params[:user]) unless (!admin? and params[:user][:effective_service_level]) - respond_with @user - end - - def deactivate - @user.enabled = false - @user.save - respond_with @user - end - - def enable - @user.enabled = true - @user.save - respond_with @user - end - - def destroy - @user.account.destroy - flash[:notice] = I18n.t(:account_destroyed) - # admins can destroy other users - if @user != current_user - redirect_to users_url - else - # let's remove the invalid session - logout - redirect_to bye_url - end - end - -end diff --git a/users/app/controllers/v1/messages_controller.rb b/users/app/controllers/v1/messages_controller.rb deleted file mode 100644 index f71d0f1..0000000 --- a/users/app/controllers/v1/messages_controller.rb +++ /dev/null @@ -1,25 +0,0 @@ -module V1 - class MessagesController < ApplicationController - - skip_before_filter :verify_authenticity_token - before_filter :require_token - - respond_to :json - - def index - render json: (current_user ? current_user.messages : [] ) - end - - def update - message = Message.find(params[:id]) - if (message and current_user) - message.mark_as_read_by(current_user) - message.save - render json: true - else - render json: false - end - end - - end -end diff --git a/users/app/controllers/v1/sessions_controller.rb b/users/app/controllers/v1/sessions_controller.rb deleted file mode 100644 index eae3a1e..0000000 --- a/users/app/controllers/v1/sessions_controller.rb +++ /dev/null @@ -1,45 +0,0 @@ -module V1 - class SessionsController < ApplicationController - - skip_before_filter :verify_authenticity_token - before_filter :require_token, only: :destroy - - def new - @session = Session.new - if authentication_errors - @errors = authentication_errors - render :status => 422 - end - end - - def create - logout if logged_in? - if params['A'] - authenticate! - else - @user = User.find_by_login(params['login']) - render :json => {salt: @user.salt} - end - end - - def update - authenticate! - @token = Token.create(:user_id => current_user.id) - session[:token] = @token.id - render :json => login_response - end - - def destroy - logout - head :no_content - end - - protected - - def login_response - handshake = session.delete(:handshake) || {} - handshake.to_hash.merge(:id => current_user.id, :token => @token.id) - end - - end -end diff --git a/users/app/controllers/v1/users_controller.rb b/users/app/controllers/v1/users_controller.rb deleted file mode 100644 index 8897d01..0000000 --- a/users/app/controllers/v1/users_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -module V1 - class UsersController < UsersBaseController - - skip_before_filter :verify_authenticity_token - before_filter :fetch_user, :only => [:update] - before_filter :require_admin, :only => [:index] - before_filter :require_token, :only => [:update] - - respond_to :json - - # used for autocomplete for admins in the web ui - def index - if params[:query] - @users = User.by_login.startkey(params[:query]).endkey(params[:query].succ) - respond_with @users.map(&:login).sort - else - render :json => {'error' => 'query required', 'status' => :unprocessable_entity} - end - end - - def create - @user = Account.create(params[:user]) - respond_with @user # return ID instead? - end - - def update - @user.account.update params[:user] - respond_with @user - end - - end -end diff --git a/users/app/controllers/webfinger_controller.rb b/users/app/controllers/webfinger_controller.rb deleted file mode 100644 index 8872802..0000000 --- a/users/app/controllers/webfinger_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -class WebfingerController < ApplicationController - - respond_to :xml, :json - layout false - - def host_meta - @host_meta = Webfinger::HostMetaPresenter.new(request) - respond_with @host_meta - end - - def search - username = params[:q].split('@')[0].to_s.downcase - user = User.find_by_login(username) - raise RECORD_NOT_FOUND, 'User not found' unless user.present? - @presenter = Webfinger::UserPresenter.new(user, request) - respond_with @presenter - end - -end diff --git a/users/app/designs/message/by_user_ids_to_show.js b/users/app/designs/message/by_user_ids_to_show.js deleted file mode 100644 index e33566b..0000000 --- a/users/app/designs/message/by_user_ids_to_show.js +++ /dev/null @@ -1,7 +0,0 @@ -function (doc) { - if (doc.type === 'Message' && doc.user_ids_to_show && Array.isArray(doc.user_ids_to_show)) { - doc.user_ids_to_show.forEach(function (userId) { - emit(userId, 1); - }); - } -} diff --git a/users/app/designs/message/by_user_ids_to_show_and_created_at.js b/users/app/designs/message/by_user_ids_to_show_and_created_at.js deleted file mode 100644 index 54e4604..0000000 --- a/users/app/designs/message/by_user_ids_to_show_and_created_at.js +++ /dev/null @@ -1,9 +0,0 @@ -// not using at moment -// call with something like Message.by_user_ids_to_show_and_created_at.startkey([user_id, start_date]).endkey([user_id,end_date]) -function (doc) { - if (doc.type === 'Message' && doc.user_ids_to_show && Array.isArray(doc.user_ids_to_show)) { - doc.user_ids_to_show.forEach(function (userId) { - emit([userId, doc.created_at], 1); - }); - } -} diff --git a/users/app/designs/user/by_created_at_and_one_month_warning_not_sent.js b/users/app/designs/user/by_created_at_and_one_month_warning_not_sent.js deleted file mode 100644 index 53a95de..0000000 --- a/users/app/designs/user/by_created_at_and_one_month_warning_not_sent.js +++ /dev/null @@ -1,5 +0,0 @@ -function (doc) { - if ((doc['type'] == 'User') && (doc['created_at'] != null) && (doc['one_month_warning_sent'] == null)) { - emit(doc['created_at'], 1); - } -} diff --git a/users/app/helpers/.gitkeep b/users/app/helpers/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/users/app/helpers/email_aliases_helper.rb b/users/app/helpers/email_aliases_helper.rb deleted file mode 100644 index b56b068..0000000 --- a/users/app/helpers/email_aliases_helper.rb +++ /dev/null @@ -1,11 +0,0 @@ -module EmailAliasesHelper - - def email_alias_form(options = {}) - simple_form_for [@user, EmailAlias.new()], - :html => {:class => "form-horizontal email-alias form"}, - :validate => true do |f| - yield f - end - end - -end diff --git a/users/app/helpers/sessions_helper.rb b/users/app/helpers/sessions_helper.rb deleted file mode 100644 index 309f8b2..0000000 --- a/users/app/helpers/sessions_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module SessionsHelper -end diff --git a/users/app/helpers/users_helper.rb b/users/app/helpers/users_helper.rb deleted file mode 100644 index f56faab..0000000 --- a/users/app/helpers/users_helper.rb +++ /dev/null @@ -1,14 +0,0 @@ -module UsersHelper - - def user_form_class(*classes) - (classes + ['user', 'form', (@user.new_record? ? 'new' : 'edit')]).compact.join(' ') - end - - def wrapped(item, options = {}) - options[:as] ||= :div - content_tag options[:as], :class => dom_class(item), :id => dom_id(item) do - yield - end - end - -end diff --git a/users/app/mailers/.gitkeep b/users/app/mailers/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/users/app/models/.gitkeep b/users/app/models/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/users/app/models/account.rb b/users/app/models/account.rb deleted file mode 100644 index cf998e4..0000000 --- a/users/app/models/account.rb +++ /dev/null @@ -1,68 +0,0 @@ -# -# The Account model takes care of the livecycle of a user. -# It composes a User record and it's identity records. -# It also allows for other engines to hook into the livecycle by -# monkeypatching the create, update and destroy methods. -# There's an ActiveSupport load_hook at the end of this file to -# make this more easy. -# -class Account - - attr_reader :user - - def initialize(user = nil) - @user = user - end - - # Returns the user record so it can be used in views. - def self.create(attrs) - @user = User.create(attrs).tap do |user| - Identity.create_for user - end - end - - def update(attrs) - if attrs[:password_verifier].present? - update_login(attrs[:login]) - @user.update_attributes attrs.slice(:password_verifier, :password_salt) - end - # TODO: move into identity controller - key = update_pgp_key(attrs[:public_key]) - @user.errors.set :public_key, key.errors.full_messages - @user.save && save_identities - @user.refresh_identity - end - - def destroy - return unless @user - Identity.disable_all_for(@user) - @user.destroy - end - - protected - - def update_login(login) - return unless login.present? - @old_identity = Identity.for(@user) - @user.login = login - @new_identity = Identity.for(@user) # based on the new login - @old_identity.destination = @user.email_address # alias old -> new - end - - def update_pgp_key(key) - PgpKey.new(key).tap do |key| - if key.present? && key.valid? - @new_identity ||= Identity.for(@user) - @new_identity.set_key(:pgp, key) - end - end - end - - def save_identities - @new_identity.try(:save) && @old_identity.try(:save) - end - - # You can hook into the account lifecycle from different engines using - # ActiveSupport.on_load(:account) do ... - ActiveSupport.run_load_hooks(:account, self) -end diff --git a/users/app/models/email.rb b/users/app/models/email.rb deleted file mode 100644 index a9a503f..0000000 --- a/users/app/models/email.rb +++ /dev/null @@ -1,26 +0,0 @@ -class Email < String - include ActiveModel::Validations - - validates :email, - :format => { - :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, #local part of email is case-sensitive, so allow uppercase letter. - :message => "needs to be a valid email address" - } - - def to_partial_path - "emails/email" - end - - def to_param - to_s - end - - def email - self - end - - def handle - self.split('@').first - end - -end diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb deleted file mode 100644 index 9b97b51..0000000 --- a/users/app/models/identity.rb +++ /dev/null @@ -1,136 +0,0 @@ -class Identity < CouchRest::Model::Base - include LoginFormatValidation - - use_database :identities - - belongs_to :user - - property :address, LocalEmail - property :destination, Email - property :keys, HashWithIndifferentAccess - - validate :unique_forward - validate :alias_available - validate :address_local_email - validate :destination_email - - design do - view :by_user_id - view :by_address_and_destination - view :by_address - view :pgp_key_by_email, - map: <<-EOJS - function(doc) { - if (doc.type != 'Identity') { - return; - } - if (typeof doc.keys === "object") { - emit(doc.address, doc.keys["pgp"]); - } - } - EOJS - view :disabled, - map: <<-EOJS - function(doc) { - if (doc.type != 'Identity') { - return; - } - if (typeof doc.user_id === "undefined") { - emit(doc._id, 1); - } - } - EOJS - - end - - def self.for(user, attributes = {}) - find_for(user, attributes) || build_for(user, attributes) - end - - def self.find_for(user, attributes = {}) - attributes.reverse_merge! attributes_from_user(user) - find_by_address_and_destination [attributes[:address], attributes[:destination]] - end - - def self.build_for(user, attributes = {}) - attributes.reverse_merge! attributes_from_user(user) - Identity.new(attributes) - end - - def self.create_for(user, attributes = {}) - identity = build_for(user, attributes) - identity.save - identity - end - - def self.disable_all_for(user) - Identity.by_user_id.key(user.id).each do |identity| - identity.disable - identity.save - end - end - - def self.destroy_all_disabled - Identity.disabled.each do |identity| - identity.destroy - end - end - - def self.attributes_from_user(user) - { user_id: user.id, - address: user.email_address, - destination: user.email_address - } - end - - def enabled? - self.destination && self.user_id - end - - def disable - self.destination = nil - self.user_id = nil - end - - def keys - read_attribute('keys') || HashWithIndifferentAccess.new - end - - def set_key(type, key) - return if keys[type] == key.to_s - write_attribute('keys', keys.merge(type => key.to_s)) - end - - # for LoginFormatValidation - def login - self.address.handle - end - - protected - - def unique_forward - same = Identity.find_by_address_and_destination([address, destination]) - if same && same != self - errors.add :base, "This alias already exists" - end - end - - def alias_available - same = Identity.find_by_address(address) - if same && same.user != self.user - errors.add :base, "This email has already been taken" - end - end - - def address_local_email - return if address.valid? #this ensures it is LocalEmail - self.errors.add(:address, address.errors.messages[:email].first) #assumes only one error - end - - def destination_email - return if destination.nil? # this identity is disabled - return if destination.valid? # this ensures it is Email - self.errors.add(:destination, destination.errors.messages[:email].first) #assumes only one error #TODO - end - -end diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb deleted file mode 100644 index 2b4c65e..0000000 --- a/users/app/models/local_email.rb +++ /dev/null @@ -1,68 +0,0 @@ -class LocalEmail < Email - - BLACKLIST_FROM_RFC2142 = [ - 'postmaster', 'hostmaster', 'domainadmin', 'webmaster', 'www', - 'abuse', 'noc', 'security', 'usenet', 'news', 'uucp', - 'ftp', 'sales', 'marketing', 'support', 'info' - ] - - def self.domain - APP_CONFIG[:domain] - end - - validates :email, - :format => { - :with => /@#{domain}\Z/i, - :message => "needs to end in @#{domain}" - } - - validate :handle_allowed - - def initialize(s) - super - append_domain_if_needed - end - - def to_key - [handle] - end - - def domain - LocalEmail.domain - end - - protected - - def append_domain_if_needed - unless self.index('@') - self << '@' + domain - end - end - - def handle_allowed - errors.add(:handle, "is reserved.") if handle_reserved? - end - - def handle_reserved? - # *ARRAY in a case statement tests if ARRAY includes the handle. - case handle - when *APP_CONFIG[:handle_blacklist] - true - when *APP_CONFIG[:handle_whitelist] - false - when *BLACKLIST_FROM_RFC2142 - true - else - handle_in_passwd? - end - end - - def handle_in_passwd? - begin - !!Etc.getpwnam(handle) - rescue ArgumentError - # handle was not found - return false - end - end -end diff --git a/users/app/models/login_format_validation.rb b/users/app/models/login_format_validation.rb deleted file mode 100644 index c1fcf70..0000000 --- a/users/app/models/login_format_validation.rb +++ /dev/null @@ -1,21 +0,0 @@ -module LoginFormatValidation - extend ActiveSupport::Concern - - #TODO: Probably will replace this. Playing with using it for aliases too, but won't want it connected to login field. - - included do - # Have multiple regular expression validations so we can get specific error messages: - validates :login, - :format => { :with => /\A.{2,}\z/, - :message => "Must have at least two characters"} - validates :login, - :format => { :with => /\A[a-z\d_\.-]+\z/, - :message => "Only lowercase letters, digits, . - and _ allowed."} - validates :login, - :format => { :with => /\A[a-z].*\z/, - :message => "Must begin with a lowercase letter"} - validates :login, - :format => { :with => /\A.*[a-z\d]\z/, - :message => "Must end with a letter or digit"} - end -end diff --git a/users/app/models/message.rb b/users/app/models/message.rb deleted file mode 100644 index 424f094..0000000 --- a/users/app/models/message.rb +++ /dev/null @@ -1,29 +0,0 @@ -class Message < CouchRest::Model::Base - - use_database :messages - - property :text, String - property :user_ids_to_show, [String] - property :user_ids_have_shown, [String] # is this necessary to store? - - timestamps! - - design do - own_path = Pathname.new(File.dirname(__FILE__)) - load_views(own_path.join('..', 'designs', 'message')) - end - - def mark_as_read_by(user) - user_ids_to_show.delete(user.id) - # is it necessary to keep track of what users have already seen it? - user_ids_have_shown << user.id unless read_by?(user) - end - - def read_by?(user) - user_ids_have_shown.include?(user.id) - end - - def unread_by?(user) - user_ids_to_show.include?(user.id) - end -end diff --git a/users/app/models/pgp_key.rb b/users/app/models/pgp_key.rb deleted file mode 100644 index 66f8660..0000000 --- a/users/app/models/pgp_key.rb +++ /dev/null @@ -1,48 +0,0 @@ -class PgpKey - include ActiveModel::Validations - - KEYBLOCK_IDENTIFIERS = [ - '-----BEGIN PGP PUBLIC KEY BLOCK-----', - '-----END PGP PUBLIC KEY BLOCK-----', - ] - - # mostly for testing. - attr_accessor :keyblock - - validate :validate_keyblock_format - - def initialize(keyblock = nil) - @keyblock = keyblock - end - - def to_s - @keyblock - end - - def present? - @keyblock.present? - end - - # allow comparison with plain keyblock strings. - def ==(other) - self.equal?(other) or - # relax the comparison on line ends. - self.to_s.tr_s("\n\r", '') == other.tr_s("\r\n", '') - end - - protected - - def validate_keyblock_format - if keyblock_identifier_missing? - errors.add :public_key_block, - "does not look like an armored pgp public key block" - end - end - - def keyblock_identifier_missing? - KEYBLOCK_IDENTIFIERS.find do |identify| - !@keyblock.include?(identify) - end - end - -end diff --git a/users/app/models/service_level.rb b/users/app/models/service_level.rb deleted file mode 100644 index 299aaf1..0000000 --- a/users/app/models/service_level.rb +++ /dev/null @@ -1,19 +0,0 @@ -class ServiceLevel - - def initialize(attributes = {}) - @id = attributes[:id] || APP_CONFIG[:default_service_level] - end - - def self.authenticated_select_options - APP_CONFIG[:service_levels].map { |id,config_hash| [config_hash[:description], id] if config_hash[:name] != 'anonymous'}.compact - end - - def id - @id - end - - def config_hash - APP_CONFIG[:service_levels][@id] - end - -end diff --git a/users/app/models/session.rb b/users/app/models/session.rb deleted file mode 100644 index 0d7e10e..0000000 --- a/users/app/models/session.rb +++ /dev/null @@ -1,32 +0,0 @@ -class Session < SRP::Session - include ActiveModel::Validations - include LoginFormatValidation - - attr_accessor :login - - validates :login, :presence => true - - def initialize(user = nil, aa = nil) - super(user, aa) if user - end - - def persisted? - false - end - - def new_record? - true - end - - def to_model - self - end - - def to_key - [object_id] - end - - def to_param - nil - end -end diff --git a/users/app/models/token.rb b/users/app/models/token.rb deleted file mode 100644 index 4856c31..0000000 --- a/users/app/models/token.rb +++ /dev/null @@ -1,69 +0,0 @@ -class Token < CouchRest::Model::Base - - use_database :tokens - - belongs_to :user - - # timestamps! does not create setters and only sets updated_at - # if the object has changed and been saved. Instead of triggering - # that we rather use our own property we have control over: - property :last_seen_at, Time, accessible: false - - validates :user_id, presence: true - - design do - view :by_last_seen_at - end - - def self.expires_after - APP_CONFIG[:auth] && APP_CONFIG[:auth][:token_expires_after] - end - - def self.expired - return [] unless expires_after - by_last_seen_at.endkey(expires_after.minutes.ago) - end - - def self.destroy_all_expired - self.expired.each do |token| - token.destroy - end - end - - def authenticate - if expired? - destroy - return nil - else - touch - return user - end - end - - # Tokens can be cleaned up in different ways. - # So let's make sure we don't crash if they disappeared - def destroy_with_rescue - destroy_without_rescue - rescue RestClient::ResourceNotFound - end - alias_method_chain :destroy, :rescue - - def touch - self.last_seen_at = Time.now - save - end - - def expired? - Token.expires_after and - last_seen_at < Token.expires_after.minutes.ago - end - - def initialize(*args) - super - if new_record? - self.id = SecureRandom.urlsafe_base64(32).gsub(/^_*/, '') - self.last_seen_at = Time.now - end - end -end - diff --git a/users/app/models/unauthenticated_user.rb b/users/app/models/unauthenticated_user.rb deleted file mode 100644 index 0fc17d2..0000000 --- a/users/app/models/unauthenticated_user.rb +++ /dev/null @@ -1,6 +0,0 @@ -# The nil object for the user class -class UnauthenticatedUser < Object - - # will probably want something here to return service level as APP_CONFIG[:service_levels][0] but not sure how will be accessing. - -end diff --git a/users/app/models/user.rb b/users/app/models/user.rb deleted file mode 100644 index c297ac8..0000000 --- a/users/app/models/user.rb +++ /dev/null @@ -1,179 +0,0 @@ -class User < CouchRest::Model::Base - include LoginFormatValidation - - use_database :users - - property :login, String, :accessible => true - property :password_verifier, String, :accessible => true - property :password_salt, String, :accessible => true - - property :enabled, TrueClass, :default => true - - # these will be null by default but we shouldn't ever pull them directly, but only via the methods that will return the full ServiceLevel - property :desired_service_level_code, Integer, :accessible => true - property :effective_service_level_code, Integer, :accessible => true - - property :one_month_warning_sent, TrueClass - - before_save :update_effective_service_level - - validates :login, :password_salt, :password_verifier, - :presence => true - - validates :login, - :uniqueness => true, - :if => :serverside? - - validate :login_is_unique_alias - - validates :password_salt, :password_verifier, - :format => { :with => /\A[\dA-Fa-f]+\z/, :message => "Only hex numbers allowed" } - - validates :password, :presence => true, - :confirmation => true, - :format => { :with => /.{8}.*/, :message => "needs to be at least 8 characters long" } - - timestamps! - - design do - own_path = Pathname.new(File.dirname(__FILE__)) - load_views(own_path.join('..', 'designs', 'user')) - view :by_login - view :by_created_at - end # end of design - - def to_json(options={}) - { - :login => login, - :ok => valid? - }.to_json(options) - end - - def salt - password_salt.hex - end - - def verifier - password_verifier.hex - end - - def username - login - end - - def email_address - LocalEmail.new(login) - end - - # Since we are storing admins by login, we cannot allow admins to change their login. - def is_admin? - APP_CONFIG['admins'].include? self.login - end - - def most_recent_tickets(count=3) - Ticket.for_user(self).limit(count).all #defaults to having most recent updated first - end - - def messages(unseen = true) - #TODO for now this only shows unseen messages. Will we ever want seen ones? Is it necessary to store? - - # we don't want to emit all the userids associated with a message, so only emit id and text. - Message.by_user_ids_to_show.key(self.id).map { |message| [message.id, message.text] } - - end - - # DEPRECATED - # - # Please set the key on the identity directly - # WARNING: This will not be serialized with the user record! - # It is only a workaround for the key form. - def public_key=(value) - identity.set_key(:pgp, value) - end - - # DEPRECATED - # - # Please access identity.keys[:pgp] directly - def public_key - identity.keys[:pgp] - end - - def account - Account.new(self) - end - - def identity - @identity ||= Identity.for(self) - end - - def refresh_identity - @identity = Identity.for(self) - end - - def desired_service_level - code = self.desired_service_level_code || APP_CONFIG[:default_service_level] - ServiceLevel.new({id: code}) - end - - def effective_service_level - code = self.effective_service_level_code || self.desired_service_level.id - ServiceLevel.new({id: code}) - end - - - def self.send_one_month_warnings - - # To determine warnings to send, need to get all users where one_month_warning_sent is not set, and where it was created greater than or equal to 1 month ago. - # TODO: might want to further limit to enabled accounts, and, based on provider's service level configuration, for particular service levels. - users_to_warn = User.by_created_at_and_one_month_warning_not_sent.endkey(Time.now-1.month) - - users_to_warn.each do |user| - # instead of loop could use something like: - # message.user_ids_to_show = users_to_warn.map(&:id) - # but would still need to loop through users to store one_month_warning_sent - - if !@message - # create a message for today's date - # only want to create once, and only if it will be used. - @message = Message.new(:text => I18n.t(:payment_one_month_warning, :date_in_one_month => (Time.now+1.month).strftime("%Y-%d-%m"))) - end - - @message.user_ids_to_show << user.id - user.one_month_warning_sent = true - user.save - end - @message.save if @message - - end - - protected - - ## - # Validation Functions - ## - - def login_is_unique_alias - alias_identity = Identity.find_by_address(self.email_address) - return if alias_identity.blank? - if alias_identity.user != self - errors.add(:login, "has already been taken") - end - end - - def password - password_verifier - end - - # used as a condition for validations that are server side only - def serverside? - true - end - - def update_effective_service_level - # TODO: Is this always the case? Might there be a situation where the admin has set the effective service level and we don't want it changed to match the desired one? - if self.desired_service_level_code_changed? - self.effective_service_level_code = self.desired_service_level_code - end - end - -end diff --git a/users/app/views/.gitkeep b/users/app/views/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/users/app/views/emails/_email.html.haml b/users/app/views/emails/_email.html.haml deleted file mode 100644 index ea59cec..0000000 --- a/users/app/views/emails/_email.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -= wrapped(email, local_assigns) do - = email - - if local_assigns[:with].try(:include?, :delete) - = link_to(user_email_alias_path(@user, email), :method => :delete) do - %i.icon-remove - diff --git a/users/app/views/sessions/new.html.haml b/users/app/views/sessions/new.html.haml deleted file mode 100644 index 771dc97..0000000 --- a/users/app/views/sessions/new.html.haml +++ /dev/null @@ -1,10 +0,0 @@ -.span1 -.span9 - = render :partial => 'users/warnings' - %h2=t :login - = simple_form_for [:api, @session], :validate => true, :html => { :id => :new_session, :class => 'form-horizontal' } do |f| - = f.input :login, :required => false, :label => t(:username), :input_html => { :id => :srp_username } - = f.input :password, :required => false, :input_html => { :id => :srp_password } - .form-actions - = f.button :submit, :value => t(:login), :class => 'btn-primary' - = link_to t(:cancel), home_path, :class => 'btn' diff --git a/users/app/views/sessions/new.json.erb b/users/app/views/sessions/new.json.erb deleted file mode 100644 index 36154b8..0000000 --- a/users/app/views/sessions/new.json.erb +++ /dev/null @@ -1,3 +0,0 @@ -{ -"errors": <%= raw @errors.to_json %> -} diff --git a/users/app/views/users/_change_password.html.haml b/users/app/views/users/_change_password.html.haml deleted file mode 100644 index 425e3ee..0000000 --- a/users/app/views/users/_change_password.html.haml +++ /dev/null @@ -1,21 +0,0 @@ --# --# CHANGE PASSWORD --# --# * everything about this form is handled with javascript. So take care when changing any ids. --# * the login is required when changing the password because it is used as part of the salt when calculating the password verifier. --# however, we don't want the user to change their login without generating a new key, so we hide the ui for this --# (although it works perfectly fine to change username if the field was visible). --# - -- form_options = {:url => '/not-used', :html => {:class => user_form_class('form-horizontal'), :id => 'update_login_and_password', :data => {token: session[:token]}}, :validate => true} -= simple_form_for @user, form_options do |f| - %legend= t(:change_password) - = hidden_field_tag 'user_param', @user.to_param - .hidden - = f.input :login, :label => t(:username), :required => false, :input_html => {:id => :srp_username} - = f.input :password, :required => false, :validate => true, :input_html => { :id => :srp_password } - = f.input :password_confirmation, :required => false, :input_html => { :id => :srp_password_confirmation } - .control-group - .controls - = f.submit t(:save), :class => 'btn btn-primary' - diff --git a/users/app/views/users/_change_pgp_key.html.haml b/users/app/views/users/_change_pgp_key.html.haml deleted file mode 100644 index e465125..0000000 --- a/users/app/views/users/_change_pgp_key.html.haml +++ /dev/null @@ -1,13 +0,0 @@ --# --# CHANGE PGP KEY --# --# this will be replaced by a identities controller/view at some point --# - -- form_options = {:html => {:class => user_form_class('form-horizontal'), :id => 'update_pgp_key', :data => {token: session[:token]}}, :validate => true} -= simple_form_for [:api, @user], form_options do |f| - %legend= t(:advanced_options) - = f.input :public_key, :as => :text, :hint => t(:use_ascii_key), :input_html => {:class => "full-width", :rows => 4} - .control-group - .controls - = f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."} diff --git a/users/app/views/users/_change_service_level.html.haml b/users/app/views/users/_change_service_level.html.haml deleted file mode 100644 index 61e67d9..0000000 --- a/users/app/views/users/_change_service_level.html.haml +++ /dev/null @@ -1,18 +0,0 @@ --# TODO: probably won't want here, but here for now. Also, we will need way to ensure payment if they pick a non-free plan. --# --# SERVICE LEVEL --# -- if APP_CONFIG[:service_levels] - - form_options = {:html => {:class => user_form_class('form-horizontal'), :id => 'update_service_level', :data => {token: session[:token]}}, :validate => true} - = simple_form_for @user, form_options do |f| - %legend= t(:service_level) - - if @user != current_user - = t(:desired_service_level) - = f.select :desired_service_level_code, ServiceLevel.authenticated_select_options, :selected => @user.desired_service_level.id - - if @user != current_user - %p - = t(:effective_service_level) - = f.select :effective_service_level_code, ServiceLevel.authenticated_select_options, :selected => @user.effective_service_level.id - .control-group - .controls - = f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."} diff --git a/users/app/views/users/_destroy_account.html.haml b/users/app/views/users/_destroy_account.html.haml deleted file mode 100644 index 445f3c4..0000000 --- a/users/app/views/users/_destroy_account.html.haml +++ /dev/null @@ -1,27 +0,0 @@ --# --# DESTROY ACCOUNT --# - -%legend - - if @user == current_user - = t(:destroy_my_account) - - else - = t(:admin_destroy_account, :username => @user.login) -%p= t(:destroy_account_info) -= link_to user_path(@user), :method => :delete, :confirm => t(:are_you_sure), :class => "btn btn-danger" do - %i.icon-remove.icon-white - = t(:destroy_my_account) -- if @user != current_user and @user.enabled? - %legend - = t(:deactivate_account, :username => @user.login) - %p= t(:deactivate_description) - = link_to deactivate_user_path(@user), :method => :post, :class => "btn btn-warning" do - %i.icon-pause.icon-white - = t(:deactivate) -- elsif @user != current_user and !@user.enabled? - %legend - = t(:enable_account, :username => @user.login) - %p= t(:enable_description) - = link_to enable_user_path(@user), :method => :post, :class => "btn btn-warning" do - %i.icon-ok.icon-white - = t(:enable) diff --git a/users/app/views/users/_edit.html.haml b/users/app/views/users/_edit.html.haml deleted file mode 100644 index 1d2b68a..0000000 --- a/users/app/views/users/_edit.html.haml +++ /dev/null @@ -1,14 +0,0 @@ --# --# edit user form, used by both show and edit actions. --# --# We render a bunch of forms here. Which we use depends upon config settings --# user_actions and admin_actions. They both include an array of actions --# allowed to users and admins. --# Possible forms are: --# 'change_password' --# 'change_pgp_key' --# 'change_service_level' --# 'destroy_account' -- actions = APP_CONFIG[admin? ? :admin_actions : :user_actions] || [] -- actions.each do |action| - = render action diff --git a/users/app/views/users/_user.html.haml b/users/app/views/users/_user.html.haml deleted file mode 100644 index 583d22f..0000000 --- a/users/app/views/users/_user.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -%tr - %td= link_to user.login, user - %td= l(user.created_at, :format => :short) - %td= l(user.updated_at, :format => :short) diff --git a/users/app/views/users/_warnings.html.haml b/users/app/views/users/_warnings.html.haml deleted file mode 100644 index 79ab103..0000000 --- a/users/app/views/users/_warnings.html.haml +++ /dev/null @@ -1,12 +0,0 @@ -%noscript - %div.alert.alert-error=t :js_required_html -#cookie_warning.alert.alert-error{:style => "display:none"} - =t :cookie_disabled_warning -:javascript - document.cookie = "testing=cookies_enabled; path=/"; - if(document.cookie.indexOf("testing=cookies_enabled") < 0) - { - document.getElementById('cookie_warning').style.display = 'block'; - } else { - document.getElementById('cookie_warning').style.display = 'none'; - } \ No newline at end of file diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml deleted file mode 100644 index 434c025..0000000 --- a/users/app/views/users/edit.html.haml +++ /dev/null @@ -1 +0,0 @@ -= render 'edit' diff --git a/users/app/views/users/index.html.haml b/users/app/views/users/index.html.haml deleted file mode 100644 index fc1001e..0000000 --- a/users/app/views/users/index.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -- @show_navigation = false - -= form_tag users_path, :method => :get, :class => "form-search" do - .input-append - = text_field_tag :query, params[:query], :id => 'user-typeahead', :class => "search-query", :autocomplete => :off - %button.btn{:type => :submit}= t(:search) - -%table.table.table-striped - %tr - %th= t(:username) - %th= t(:created) - %th= t(:updated) - = render @users.all diff --git a/users/app/views/users/new.html.haml b/users/app/views/users/new.html.haml deleted file mode 100644 index aecf831..0000000 --- a/users/app/views/users/new.html.haml +++ /dev/null @@ -1,19 +0,0 @@ --# --# This form is handled entirely by javascript, so take care when changing element ids. --# - -- form_options = {:url => '/not-used', :html => {:id => 'new_user', :class => user_form_class('form-horizontal')}, :validate => true} - -.span1 -.span9 - = render :partial => 'warnings' - %h2=t :signup - = simple_form_for(@user, form_options) do |f| - %legend= t(:signup_message) - = f.input :login, :label => t(:username), :required => false, :input_html => { :id => :srp_username } - = f.input :password, :required => false, :validate => true, :input_html => { :id => :srp_password } - = f.input :password_confirmation, :required => false, :validate => true, :input_html => { :id => :srp_password_confirmation } - .form-actions - = f.button :submit, :value => t(:signup), :class => 'btn btn-primary' - = link_to t(:cancel), home_path, :class => 'btn' - diff --git a/users/app/views/users/show.html.haml b/users/app/views/users/show.html.haml deleted file mode 100644 index c587017..0000000 --- a/users/app/views/users/show.html.haml +++ /dev/null @@ -1,25 +0,0 @@ -.overview - - %h2.first= t(:overview_welcome, :username => @user.login) - - - if admin? - %p - = t(:created) - = @user.created_at - %br - = t(:updated) - = @user.updated_at - %br - = t(:enabled) - = @user.enabled? - - %p= t(:overview_intro) - - %ul.unstyled - %li= icon('user') + link_to(t(:overview_account), edit_user_path(@user)) - - # %li= icon('envelope') + link_to(t(:overview_email), {insert path for user identities, presuambly} - %li= icon('question-sign') + link_to(t(:overview_tickets), user_tickets_path(@user)) - %li= icon('shopping-cart') + link_to(t(:overview_billing), billing_top_link(@user)) if APP_CONFIG[:billing] - .container-fluid - .row-fluid - = home_page_buttons(true) \ No newline at end of file diff --git a/users/app/views/v1/sessions/new.json.erb b/users/app/views/v1/sessions/new.json.erb deleted file mode 100644 index 36154b8..0000000 --- a/users/app/views/v1/sessions/new.json.erb +++ /dev/null @@ -1,3 +0,0 @@ -{ -"errors": <%= raw @errors.to_json %> -} diff --git a/users/app/views/webfinger/host_meta.xml.erb b/users/app/views/webfinger/host_meta.xml.erb deleted file mode 100644 index cfcbcc0..0000000 --- a/users/app/views/webfinger/host_meta.xml.erb +++ /dev/null @@ -1,11 +0,0 @@ - - - - <%= @host_meta.subject %> - - <%- @host_meta.links.each do |rel, link| %> - - <%- end %> - diff --git a/users/app/views/webfinger/search.xml.erb b/users/app/views/webfinger/search.xml.erb deleted file mode 100644 index 7328552..0000000 --- a/users/app/views/webfinger/search.xml.erb +++ /dev/null @@ -1,7 +0,0 @@ - - - <%= @presenter.subject %> - <%- @presenter.links.each do |rel, link| %> - type=<%=link[:type]%> href="<%= link[:key] %>"/> - <% end %> - -- cgit v1.2.3