summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-04-30 00:32:33 -0700
committerelijah <elijah@riseup.net>2015-04-30 00:32:33 -0700
commit63871baf6061668b162972193c55b5a8f7490797 (patch)
treeca8cd5fbab18cbe59b728a123f450140ed98f519 /app
parentc3b133cb6f02003ab934e5008e108f489ace4158 (diff)
added support for email notifications of ticket changes
Diffstat (limited to 'app')
-rw-r--r--app/controllers/controller_extension/flash.rb18
-rw-r--r--app/controllers/users_controller.rb5
-rw-r--r--app/mailers/.gitkeep0
-rw-r--r--app/models/anonymous_user.rb4
-rw-r--r--app/models/user.rb10
-rw-r--r--app/views/users/_contact_email.html.haml9
6 files changed, 42 insertions, 4 deletions
diff --git a/app/controllers/controller_extension/flash.rb b/app/controllers/controller_extension/flash.rb
index 1642141..45072cf 100644
--- a/app/controllers/controller_extension/flash.rb
+++ b/app/controllers/controller_extension/flash.rb
@@ -4,9 +4,13 @@ module ControllerExtension::Flash
protected
def flash_for(resource, options = {})
- return unless resource.changed?
- add_flash_message_for resource
- add_flash_errors_for resource if options[:with_errors]
+ if resource.is_a? Exception
+ add_flash_message_for_exception resource
+ else
+ return unless resource.changed?
+ add_flash_message_for resource
+ add_flash_errors_for resource if options[:with_errors]
+ end
end
def add_flash_message_for(resource)
@@ -40,4 +44,12 @@ module ControllerExtension::Flash
flash[:error] += "<br>"
flash[:error] += resource.errors.full_messages.join(". <br>")
end
+
+ #
+ # This is pretty crude. It would be good to l10n in the future.
+ #
+ def add_flash_message_for_exception(exc)
+ flash[:error] = exc.to_s
+ end
+
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index dcf7607..3943afc 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -40,7 +40,10 @@ class UsersController < ApplicationController
## 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
+ if @user.valid?
+ flash[:notice] = I18n.t(:changes_saved)
+ end
+ respond_with @user, :location => edit_user_path(@user)
end
def deactivate
diff --git a/app/mailers/.gitkeep b/app/mailers/.gitkeep
deleted file mode 100644
index e69de29..0000000
--- a/app/mailers/.gitkeep
+++ /dev/null
diff --git a/app/models/anonymous_user.rb b/app/models/anonymous_user.rb
index 87239eb..0c1f540 100644
--- a/app/models/anonymous_user.rb
+++ b/app/models/anonymous_user.rb
@@ -28,4 +28,8 @@ class AnonymousUser < Object
def messages
[]
end
+
+ def is_anonymous?
+ true
+ end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 52e20dd..d44df40 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -6,6 +6,8 @@ class User < CouchRest::Model::Base
property :login, String, :accessible => true
property :password_verifier, String, :accessible => true
property :password_salt, String, :accessible => true
+ property :contact_email, String, :accessible => true
+ property :contact_email_key, String, :accessible => true
property :enabled, TrueClass, :default => true
@@ -33,6 +35,10 @@ class User < CouchRest::Model::Base
:confirmation => true,
:format => { :with => /.{8}.*/, :message => "needs to be at least 8 characters long" }
+ validates :contact_email, :allow_blank => true,
+ :email => true,
+ :mx_with_fallback => true
+
timestamps!
design do
@@ -90,6 +96,10 @@ class User < CouchRest::Model::Base
APP_CONFIG['admins'].include? self.login
end
+ def is_anonymous?
+ false
+ end
+
def most_recent_tickets(count=3)
Ticket.for_user(self).limit(count).all #defaults to having most recent updated first
end
diff --git a/app/views/users/_contact_email.html.haml b/app/views/users/_contact_email.html.haml
new file mode 100644
index 0000000..ad768b7
--- /dev/null
+++ b/app/views/users/_contact_email.html.haml
@@ -0,0 +1,9 @@
+%legend= t(:contact_email)
+= simple_form_for @user, {:validate => true} do |f|
+ %p= t(:contact_email_info)
+ = f.input :contact_email, :label => false
+ -# %p= t(:public_key)
+ -# = f.text_area :contact_email_key, {:class => "full-width", :rows => 4}
+ .control-group
+ .controls
+ = f.submit t(:save), :class => 'btn', :data => {"loading-text" => "Saving..."} \ No newline at end of file