summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/service_level.rb8
-rw-r--r--app/models/user.rb4
-rw-r--r--config/defaults.yml5
-rw-r--r--engines/support/app/controllers/tickets_controller.rb1
-rw-r--r--engines/support/test/integration/create_ticket_test.rb28
-rw-r--r--test/factories.rb5
-rw-r--r--test/support/browser_integration_test.rb2
7 files changed, 50 insertions, 3 deletions
diff --git a/app/models/service_level.rb b/app/models/service_level.rb
index 5dd8838..a8df55b 100644
--- a/app/models/service_level.rb
+++ b/app/models/service_level.rb
@@ -24,6 +24,14 @@ class ServiceLevel
end
end
+ def provides?(service)
+ services.include? service
+ end
+
+ def services
+ config_hash[:services] || []
+ end
+
protected
def limited_cert?
diff --git a/app/models/user.rb b/app/models/user.rb
index c297ac8..a809879 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -62,7 +62,9 @@ class User < CouchRest::Model::Base
end
def email_address
- LocalEmail.new(login)
+ if effective_service_level.provides?('email')
+ LocalEmail.new(login)
+ end
end
# Since we are storing admins by login, we cannot allow admins to change their login.
diff --git a/config/defaults.yml b/config/defaults.yml
index 47cb641..1c7e694 100644
--- a/config/defaults.yml
+++ b/config/defaults.yml
@@ -54,12 +54,17 @@ service_levels: &service_levels
description: "free account, with rate limited VPN"
eip_rate_limit: true
storage: 100
+ services:
+ - eip
2:
name: premium
description: "premium account, with unlimited vpn"
rate:
USD: 10
EUR: 10
+ services:
+ - eip
+ - email
default_service_level: 1
development:
diff --git a/engines/support/app/controllers/tickets_controller.rb b/engines/support/app/controllers/tickets_controller.rb
index d552209..8ec8e4d 100644
--- a/engines/support/app/controllers/tickets_controller.rb
+++ b/engines/support/app/controllers/tickets_controller.rb
@@ -22,7 +22,6 @@ class TicketsController < ApplicationController
@ticket.comments.last.posted_by = current_user.id
@ticket.comments.last.private = false unless admin?
@ticket.created_by = current_user.id
- @ticket.email = current_user.email_address if current_user.email_address
if @ticket.save
flash[:notice] = t(:thing_was_successfully_created, :thing => t(:ticket))
diff --git a/engines/support/test/integration/create_ticket_test.rb b/engines/support/test/integration/create_ticket_test.rb
index 2583fc7..59b263e 100644
--- a/engines/support/test/integration/create_ticket_test.rb
+++ b/engines/support/test/integration/create_ticket_test.rb
@@ -25,4 +25,32 @@ class CreateTicketTest < BrowserIntegrationTest
assert page.has_content?("is invalid")
end
+ test "prefills email when user has email service" do
+ login FactoryGirl.create(:premium_user)
+ visit '/'
+ click_on "Support Tickets"
+ click_on "New Ticket"
+ email = "#{@user.login}@#{APP_CONFIG[:domain]}"
+ assert_equal email, find_field('Email').value
+ end
+
+ test "no prefill of email without email service" do
+ login
+ visit '/'
+ click_on "Support Tickets"
+ click_on "New Ticket"
+ assert_equal "", find_field('Email').value
+ end
+
+ test "cleared email field should remain clear" do
+ login FactoryGirl.create(:premium_user)
+ visit '/'
+ click_on "Support Tickets"
+ click_on "New Ticket"
+ fill_in 'Subject', with: 'test ticket'
+ fill_in 'Email', with: ''
+ fill_in 'Description', with: 'description of the problem goes here'
+ click_on 'Create Ticket'
+ assert_nil Ticket.last.email
+ end
end
diff --git a/test/factories.rb b/test/factories.rb
index ac9333c..bebda5c 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -22,6 +22,11 @@ FactoryGirl.define do
admin.stubs(:is_admin?).returns(true)
end
end
+
+ factory :premium_user do
+ effective_service_level_code 2
+ end
+
end
factory :token do
diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb
index 836eb63..dbd56a9 100644
--- a/test/support/browser_integration_test.rb
+++ b/test/support/browser_integration_test.rb
@@ -55,7 +55,7 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest
# currently this only works for tests with poltergeist.
def login(user = nil)
- user ||= @user ||= FactoryGirl.create(:user)
+ @user ||= user ||= FactoryGirl.create(:user)
token = Token.create user_id: user.id
page.driver.add_header "Authorization",
'Token token="' + token.to_s + '"'