Skip to content

Commit

Permalink
Merge pull request #217 from CDLUC3/mobile-ready
Browse files Browse the repository at this point in the history
Fixes for institutional branding, accessibility and mobile responsiveness
  • Loading branch information
briri committed Oct 29, 2018
2 parents f0a9cc3 + 39b7db5 commit 32e8d7d
Show file tree
Hide file tree
Showing 97 changed files with 2,474 additions and 3,286 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public/videos/*
app/views/branded/*
app/assets
config/locales/static_pages/*.yml
lib/assets/images/homepage

# Ignore gemfile.lock
#Gemfile.lock
Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ group :test do
gem 'minitest-reporters'
gem 'rack-test'
gem 'webmock'
gem 'sqlite3'
end

group :development do
Expand Down
61 changes: 31 additions & 30 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ansi (1.5.0)
arel (6.0.4)
bcrypt (3.1.11)
better_errors (2.4.0)
bcrypt (3.1.12)
better_errors (2.5.0)
coderay (>= 1.0.0)
erubi (>= 1.0.0)
rack (>= 0.9.0)
Expand All @@ -56,7 +57,7 @@ GEM
crass (1.0.4)
daemons (1.2.6)
debug_inspector (0.0.3)
devise (4.4.3)
devise (4.5.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 6.0)
Expand All @@ -71,18 +72,18 @@ GEM
rack (>= 1.3)
erubi (1.7.1)
erubis (2.7.0)
eventmachine (1.2.6)
faraday (0.9.2)
eventmachine (1.2.7)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
fast_gettext (1.6.0)
feedjira (2.1.4)
fast_gettext (1.7.0)
feedjira (2.2.0)
faraday (>= 0.9)
faraday_middleware (>= 0.9)
loofah (>= 2.0)
sax-machine (>= 1.0)
flag_shih_tzu (0.3.19)
flag_shih_tzu (0.3.22)
gettext (3.2.9)
locale (>= 2.0.5)
text (>= 1.3.0)
Expand All @@ -97,15 +98,15 @@ GEM
activesupport (>= 4.2.0)
hashdiff (0.3.7)
hashie (3.5.7)
htmltoword (1.0.0)
htmltoword (1.1.0)
actionpack
nokogiri
rubyzip (>= 1.0)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jbuilder (2.6.4)
activesupport (>= 3.0.0)
multi_json (>= 1.2)
json (2.1.0)
jwt (1.5.6)
kaminari (1.1.1)
Expand All @@ -120,18 +121,18 @@ GEM
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
ledermann-rails-settings (2.4.2)
ledermann-rails-settings (2.4.3)
activerecord (>= 3.1)
locale (2.1.2)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mini_mime (>= 0.1.1)
mini_mime (1.0.0)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.11.3)
minitest-reporters (1.2.0)
minitest-reporters (1.3.5)
ansi
builder
minitest (>= 5.0)
Expand All @@ -140,7 +141,7 @@ GEM
multi_xml (0.6.0)
multipart-post (2.0.0)
mysql2 (0.4.10)
nokogiri (1.8.2)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
oauth2 (1.4.0)
faraday (>= 0.8, < 0.13)
Expand All @@ -163,9 +164,10 @@ GEM
pg (0.19.0)
po_to_json (1.0.1)
json (>= 1.6.0)
protected_attributes (1.1.3)
protected_attributes (1.1.4)
activemodel (>= 4.0.1, < 5.0)
pundit (1.1.0)
public_suffix (3.0.3)
pundit (2.0.0)
activesupport (>= 3.0.0)
rack (1.6.10)
rack-test (0.6.3)
Expand Down Expand Up @@ -195,24 +197,24 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.3.1)
recaptcha (4.8.0)
recaptcha (4.12.0)
json
redcarpet (3.4.0)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
ruby-progressbar (1.9.0)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
ruby-progressbar (1.10.0)
ruby_dig (0.0.2)
rubyzip (1.2.1)
rubyzip (1.2.2)
safe_yaml (1.0.4)
sax-machine (1.3.2)
sprockets (3.7.1)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
text (1.3.1)
thin (1.7.2)
daemons (~> 1.0, >= 1.0.9)
Expand All @@ -228,12 +230,12 @@ GEM
activemodel (>= 4.2)
debug_inspector
railties (>= 4.2)
webmock (3.4.1)
webmock (3.4.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
wicked_pdf (1.1.0)
wkhtmltopdf-binary (0.12.3.1)
wkhtmltopdf-binary (0.12.4)

PLATFORMS
ruby
Expand Down Expand Up @@ -270,7 +272,6 @@ DEPENDENCIES
redcarpet
responders (~> 2.0)
ruby_dig
sqlite3
thin
web-console
webmock
Expand All @@ -281,4 +282,4 @@ RUBY VERSION
ruby 2.4.4p296

BUNDLED WITH
1.16.2
1.16.3
45 changes: 25 additions & 20 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
handle_omniauth(scheme)
end
end

##
# Processes callbacks from an omniauth provider and directs the user to
# Processes callbacks from an omniauth provider and directs the user to
# the appropriate page:
# Not logged in and uid had no match ---> Sign Up page
# Not logged in and uid had a match ---> Sign In and go to Home Page
Expand All @@ -24,23 +24,23 @@ def handle_omniauth(scheme)
# ------------------------------------
# START DMPTool customization
#user = User.from_omniauth(request.env["omniauth.auth"].nil? ? request.env : request.env["omniauth.auth"])

omniauth = (request.env["omniauth.auth"].nil? ? request.env : request.env["omniauth.auth"])
user = User.from_omniauth(omniauth)
omniauth_info = (omniauth.nil? ? {} : (omniauth.info.nil? ? {} : omniauth.info))
# END DMPTool customization
# ------------------------------------

# If the user isn't logged in
if current_user.nil?
if current_user.nil?

# ------------------------------------
# START DMPTool customization
# If the uid didn't have a match in the system send them to register
#if user.nil?
#session["devise.#{scheme.name.downcase}_data"] = request.env["omniauth.auth"]
#redirect_to new_user_registration_url

# Otherwise sign them in
#else
# Until ORCID becomes supported as a login method
Expand All @@ -52,36 +52,37 @@ def handle_omniauth(scheme)
#redirect_to new_user_registration_url
#end
#end

# If the uid didn't have a match in the system then attempt to find them by email
if user.nil?
user = User.where_case_insensitive('email', omniauth_info.email).first unless omniauth_info.email.nil?
email = extract_omniauth_email(omniauth_info)
user = User.where_case_insensitive('email', email).first unless email.blank?
# If we could not find the email
if user.nil?
# Extract as much info as we can from the omniauth response
firstname = omniauth_info.givenname
surname = omniauth_info.sn

if omniauth_info.name.present? && (firstname.nil? || surname.nil?)
names = omniauth_info.name.split(' ')
firstname = names[0]
surname = names[names.length - 1] if names.length > 1
end

idp = OrgIdentifier.where('LOWER(identifier) = ?', omniauth_info.identity_provider.downcase).first if omniauth_info.identity_provider.present?
org = Org.find_by(id: idp.org_id) if idp.present?
pwd = SecureRandom.uuid

# Generate a new user object which will be used to prepopulate the create
# account form
user = User.new(email: omniauth_info.email, org: org, password: pwd,
firstname: firstname, surname: surname)

session["devise.#{scheme.name.downcase}_data"] = omniauth
flash[:notice] = _('It looks like this is your first time logging in. Please verify and complete the information below to finish creating an account.')
render 'devise/registrations/new', locals: { user: user, orgs: Org.participating_as_array.sort{ |a, b| a.name <=> b.name } }
else
if UserIdentifier.create(identifier_scheme: scheme,
if UserIdentifier.create(identifier_scheme: scheme,
identifier: omniauth.uid,
user: user)
set_flash_message(:notice, :success, kind: 'your institutional credentials')
Expand All @@ -91,7 +92,7 @@ def handle_omniauth(scheme)
flash[:notice] = _('Unable to create your account at this time.')
redirect_to new_user_registration_url
end
end
end
# Otherwise sign them in
else
# Until ORCID becomes supported as a login method
Expand All @@ -105,29 +106,29 @@ def handle_omniauth(scheme)
end
# END DMPTool customization
# ------------------------------------

# The user is already logged in and just registering the uid with us
else
# If the user could not be found by that uid then attach it to their record
if user.nil?
if UserIdentifier.create(identifier_scheme: scheme,
if UserIdentifier.create(identifier_scheme: scheme,
identifier: request.env["omniauth.auth"].uid,
user: current_user)

flash[:notice] = _('Your account has been successfully created.')
else
flash[:alert] = _('Unable to create your account.')
end

else
# If a user was found but does NOT match the current user then the identifier has
# already been attached to another account (likely the user has 2 accounts)
identifier = UserIdentifier.where(identifier: request.env["omniauth.auth"].uid).first
if identifier.user.id != current_user.id
flash[:alert] = _("The current #{scheme.description} iD has been already linked to a user with email #{identifier.user.email}")
end
# Otherwise, the identifier was found and it matches the one already associated

# Otherwise, the identifier was found and it matches the one already associated
# with the current user so nothing else needs to be done
end

Expand All @@ -140,4 +141,8 @@ def handle_omniauth(scheme)
def failure
redirect_to root_path
end

def extract_omniauth_email(hash)
hash.fetch(:email, '').split(';')[0]
end
end
20 changes: 14 additions & 6 deletions app/models/org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ class Org < ActiveRecord::Base
# Validators
validates :name, presence: {message: _("can't be blank")}, uniqueness: {message: _("must be unique")}
# allow validations for logo upload
dragonfly_accessor :logo do
after_assign :resize_image
end
validates_property :format, of: :logo, in: ['jpeg', 'png', 'gif','jpg','bmp'], message: _("must be one of the following formats: jpeg, jpg, png, gif, bmp")

# Start DMPTool Customization
# ---------------------------------------
# Commenting out the logo resizer. We adjust the logo size via CSS
#dragonfly_accessor :logo do
# after_assign :resize_image
#end
dragonfly_accessor :logo
# ---------------------------------------
# End DMPTool Customization

validates_property :format, of: :logo, in: ['jpeg', 'png', 'gif', 'jpg', 'bmp'], message: _("must be one of the following formats: jpeg, jpg, png, gif, bmp")
validates_size_of :logo, maximum: 500.kilobytes, message: _("can't be larger than 500KB")

##
Expand Down Expand Up @@ -148,11 +156,11 @@ def plans
Plan.includes(:template, :phases, :roles, :users).joins(:roles, :users).where('users.org_id = ? AND roles.access IN (?)',
self.id, Role.access_values_for(:owner).concat(Role.access_values_for(:administrator)))
end

def grant_api!(token_permission_type)
self.token_permission_types << token_permission_type unless self.token_permission_types.include? token_permission_type
end

# START DMPTool customization
# ---------------------------------------------------------
# DMPTool participating institution helpers
Expand Down
Loading

0 comments on commit 32e8d7d

Please sign in to comment.