diff --git a/Gemfile.lock b/Gemfile.lock
index d981efe..31724f1 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,6 +1,10 @@
GIT
remote: git://github.com/activeadmin/activeadmin.git
+<<<<<<< HEAD
+ revision: cc178ad0ebe1b74729eeaa59d5c7ad9b82ed7837
+=======
revision: 0a5a15b88bffbe5efad7ff2a072ec4fe6eb09511
+>>>>>>> master
specs:
activeadmin (1.0.0.pre4)
arbre (~> 1.0, >= 1.0.2)
@@ -74,7 +78,12 @@
thor (~> 0.19)
builder (3.2.2)
byebug (9.0.5)
+<<<<<<< HEAD
+ cancancan (1.15.0)
+ capybara (2.8.0)
+=======
capybara (2.8.1)
+>>>>>>> master
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
diff --git a/app/assets/stylesheets/admin.css.less b/app/assets/stylesheets/admin.css.less
index d3b5db0..05664c9 100644
--- a/app/assets/stylesheets/admin.css.less
+++ b/app/assets/stylesheets/admin.css.less
@@ -1164,6 +1164,9 @@
padding:0 2px 10px 0;
}
+td.organisation-logo {
+ padding: 0 25px 10px 25px;
+}
table.dmp_details_table {
margin: 0 0 0 0;
@@ -1704,6 +1707,5 @@
width: 140px;
float: right;
margin-left: 1px;
- }
-
-}
\ No newline at end of file
+ }
+}
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 2cc96a2..5eb574e 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -28,9 +28,10 @@
elsif user_signed_in? and !current_user[:language_id].nil?
I18n.locale = Language.find_by_id(current_user[:language_id]).abbreviation
# if user has set preferred language use it
- elsif false # TODO
- # use user's organization language, keep in mine the "OTHER ORG" edge case which should use english
+ elsif user_signed_in? and current_user.organisation.present? and !current_user.organisation[:language_id].nil?
+ I18n.locale = Language.find_by_id(current_user.organisation[:language_id]).abbreviation
+ # use user's organization language, keep in mine the "OTHER ORG" edge case which should use default language
else
# just use the default language, line can be commented out, included just for clarity
I18n.locale = I18n.default_locale
diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb
index 805bee9..16ea960 100644
--- a/app/controllers/organisations_controller.rb
+++ b/app/controllers/organisations_controller.rb
@@ -60,8 +60,12 @@
def admin_update
@organisation = authorize Organisation.find(params[:id])
@organisation.banner_text = params["org_banner_text"]
+ @organisation.logo = params[:organisation][:logo] if params[:organisation][:logo]
+ assign_params = params[:organisation].dup
+ assign_params.delete(:logo)
+
respond_to do |format|
- if @organisation.update_attributes(params[:organisation])
+ if @organisation.update_attributes(assign_params)
format.html { redirect_to admin_show_organisation_path(params[:id]), notice: I18n.t("admin.org_updated_message") }
format.json { head :no_content }
else
diff --git a/app/controllers/token_permission_types_controller.rb b/app/controllers/token_permission_types_controller.rb
index ad9b7bb..5d5c3fc 100644
--- a/app/controllers/token_permission_types_controller.rb
+++ b/app/controllers/token_permission_types_controller.rb
@@ -1,12 +1,9 @@
class TokenPermissionTypesController < ApplicationController
-
-
- def index
- authorize TokenPermissionType
- @user = current_user
- respond_to do |format|
- format.html
- end
+ def index
+ authorize TokenPermissionType
+ @user = current_user
+ respond_to do |format|
+ format.html
end
-
+ end
end
\ No newline at end of file
diff --git a/app/models/organisation.rb b/app/models/organisation.rb
index a00ff86..4db9796 100644
--- a/app/models/organisation.rb
+++ b/app/models/organisation.rb
@@ -1,31 +1,44 @@
+#require 'validators/email_validator'
+
class Organisation < ActiveRecord::Base
include GlobalHelpers
- #associations between tables
- belongs_to :organisation_type
- has_many :guidance_groups
- has_many :dmptemplates
- has_many :sections
- has_many :users, through: :user_org_roles
- has_many :option_warnings
- has_many :suggested_answers
- has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions"
+
+ extend Dragonfly::Model::Validations
- has_many :user_org_roles
+ #associations between tables
+ belongs_to :organisation_type
+ has_many :guidance_groups
+ has_many :dmptemplates
+ has_many :sections
+ has_many :users, through: :user_org_roles
+ has_many :option_warnings
+ has_many :suggested_answers
+ has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions"
- belongs_to :parent, :class_name => 'Organisation'
+ belongs_to :parent, :class_name => 'Organisation'
- has_one :language
+ has_one :language
has_many :children, :class_name => 'Organisation', :foreign_key => 'parent_id'
-# accepts_nested_attributes_for :organisation_type
accepts_nested_attributes_for :dmptemplates
accepts_nested_attributes_for :token_permission_types
- attr_accessible :abbreviation, :banner_text, :description, :domain,
- :logo_file_name, :name, :stylesheet_file_id, :target_url,
+ attr_accessible :abbreviation, :banner_text, :logo, :remove_logo, :domain,
+ :logo_file_name, :name, :stylesheet_file_id, :target_url,
:organisation_type_id, :wayfless_entity, :parent_id, :sort_name,
- :token_permission_type_ids, :language_id
+ :token_permission_type_ids, :language_id, :contact_email
+
+ validates :contact_email, email: true, allow_nil: true
+
+ # allow validations for logo upload
+ dragonfly_accessor :logo do
+ after_assign :resize_image
+ end
+
+ validates_property :height, of: :logo, in: (0..100)
+ validates_property :format, of: :logo, in: ['jpeg', 'png', 'gif','jpg','bmp']
+ validates_size_of :logo, maximum: 500.kilobytes
##
# returns the name of the organisation
@@ -167,4 +180,16 @@
end
end
end
+
+ private
+ ##
+ # checks size of logo and resizes if necessary
+ #
+ def resize_image
+ unless logo.nil?
+ if logo.height != 100
+ self.logo = logo.thumb('x100') # resize height and maintain aspect ratio
+ end
+ end
+ end
end
diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb
new file mode 100644
index 0000000..d47e7c1
--- /dev/null
+++ b/app/validators/email_validator.rb
@@ -0,0 +1,7 @@
+class EmailValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
+ record.errors[attribute] << (options[:message] || "is not a valid email address")
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/views/layouts/_dmponline_header.html.erb b/app/views/layouts/_dmponline_header.html.erb
index 35114da..65c5036 100644
--- a/app/views/layouts/_dmponline_header.html.erb
+++ b/app/views/layouts/_dmponline_header.html.erb
@@ -3,7 +3,7 @@