diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 57b504f..7e4304c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,6 +21,10 @@ @perms = user_perms & [Perm.grant_permissions, Perm.modify_templates, Perm.modify_guidance, Perm.use_api, Perm.change_org_details] end + def update_preferences + + end + ## # POST - updates the permissions for a user # redirects to the admin_index action diff --git a/app/models/user.rb b/app/models/user.rb index c1350f6..03c68ba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,10 +6,15 @@ # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable - devise :invitable, :database_authenticatable, :registerable, :recoverable, - :rememberable, :trackable, :validatable, :omniauthable, + devise :invitable, :database_authenticatable, :registerable, :recoverable, + :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:shibboleth, :orcid] + + ## + # User Notification Preferences + serialize :prefs, Hash + ## # Associations has_and_belongs_to_many :perms, join_table: :users_perms @@ -26,14 +31,14 @@ q = "%#{query}%" conditions = t[:title].matches(q) columns = %i( - grant_number identifier description principal_investigator data_contact + grant_number identifier description principal_investigator data_contact ) columns = ['grant_number', 'identifier', 'description', 'principal_investigator', 'data_contact'] columns.each {|col| conditions = conditions.or(t[col].matches(q)) } self.where(conditions) end end - + has_many :user_identifiers has_many :identifier_schemes, through: :user_identifiers @@ -41,16 +46,21 @@ # Possibly needed for active_admin # -relies on protected_attributes gem as syntax depricated in rails 4.2 #accepts_nested_attributes_for :roles - #attr_accessible :password_confirmation, :encrypted_password, :remember_me, - # :id, :email, :firstname, :last_login,:login_count, :orcid_id, - # :password, :shibboleth_id, :user_status_id, :surname, - # :user_type_id, :org_id, :skip_invitation, :other_organisation, + #attr_accessible :password_confirmation, :encrypted_password, :remember_me, + # :id, :email, :firstname, :last_login,:login_count, :orcid_id, + # :password, :shibboleth_id, :user_status_id, :surname, + # :user_type_id, :org_id, :skip_invitation, :other_organisation, # :accept_terms, :role_ids, :dmponline3, :api_token, - # :organisation, :language, :language_id, :org, :perms, + # :organisation, :language, :language_id, :org, :perms, # :confirmed_at, :org_id validates :email, email: true, allow_nil: true, uniqueness: {message: _("must be unique")} + + validates :prefs, presence: true + before_validation :create_default_preferences, if: Proc.new { |x| x.prefs.empty? } + ## user.prefs = create_default_preferences + ## # Scopes default_scope { includes(:org, :perms, :plans) } @@ -62,13 +72,13 @@ # What do they do? do they do it efficiently, and do we need them? # Determines the locale set for the user or the organisation he/she belongs - # @return String or nil + # @return String or nil def get_locale if !self.language.nil? return self.language.abbreviation elsif !self.org.nil? return self.org.get_locale - else + else return nil end end @@ -126,7 +136,7 @@ def organisation=(new_org) org_id = new_org.id unless new_org.nil? end - + ## # checks if the user is a super admin # if the user has any privelege which requires them to see the super admin page @@ -144,7 +154,7 @@ # # @return [Boolean] true if the user is an organisation admin def can_org_admin? - return self.can_grant_permissions? || self.can_modify_guidance? || + return self.can_grant_permissions? || self.can_modify_guidance? || self.can_modify_templates? || self.can_modify_org_details? end @@ -223,7 +233,7 @@ return org_type end =end - + ## # removes the api_token from the user # modifies the user model @@ -254,11 +264,11 @@ # -------------------------------------------------------------- def self.from_omniauth(auth) scheme = IdentifierScheme.find_by(name: auth.provider.downcase) - + if scheme.nil? throw Exception.new('Unknown OAuth provider: ' + auth.provider) else - joins(:user_identifiers).where('user_identifiers.identifier': auth.uid, + joins(:user_identifiers).where('user_identifiers.identifier': auth.uid, 'user_identifiers.identifier_scheme_id': scheme.id).first end end @@ -271,6 +281,29 @@ end + ## + # User Notification Preferences + def create_default_preferences + self.prefs = self.class.create_default_preferences + end + + def self.create_default_preferences + default_prefs = { + users: { + permission_granted: true, + new_comment: true + }, + owners_and_coowners: { + visibility_changed: true, + user_added: true + }, + admins: { + template_published: true, + template_unpublished: true + } + } + end + # TODO: Remove this, its never called. # this generates a reset password link for a given user # which can then be sent to them with the appropriate host @@ -278,12 +311,12 @@ =begin def reset_password_link raw, enc = Devise.token_generator.generate(self.class, :reset_password_token) - self.reset_password_token = enc + self.reset_password_token = enc self.reset_password_sent_at = Time.now.utc save(validate: false) edit_user_password_path + '?reset_password_token=' + raw end =end - + end diff --git a/app/views/devise/registrations/_password_details.html.erb b/app/views/devise/registrations/_password_details.html.erb new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/views/devise/registrations/_password_details.html.erb diff --git a/app/views/devise/registrations/_personal_details.html.erb b/app/views/devise/registrations/_personal_details.html.erb new file mode 100644 index 0000000..b72279d --- /dev/null +++ b/app/views/devise/registrations/_personal_details.html.erb @@ -0,0 +1,155 @@ +

+ <%= _("Please note that your email address is used as your username. If you change this, remember to use your new email address on sign in.") %> +

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put, class: "roadmap-form white_background"}) do |f| %> + +
+ <%= _('You can edit any of the details below.') %> + + <%= hidden_field_tag :unlink_flag, "false", id: "unlink_flag" %> + +
+ + + +
+ +
+ + +
+
+ + +
+ +
+ + + +
+ +
+ + <%= render partial: "shared/accessible_combobox", + locals: {name: "#{resource_name}[org_name]", + id: "#{resource_name}_org_name", + default_selection: @default_org, + models: @orgs, + attribute: 'name', + classes: 'fixed-width-large left-indent'} %> +
+ + <% if MANY_LANGUAGES %> +
+ <% lang = current_user.language.nil? ? FastGettext.default_locale : current_user.language.abbreviation %> + + +
+ <% end %> + + <% @identifier_schemes.each do |scheme| %> +
+ +
+ <%= render partial: 'external_identifier', + locals: {scheme: scheme, + id: current_user.identifier_for(scheme)} %> +
+
+ <% end %> + + <% unless @user.api_token.blank? %> +
+ <%= f.label :api_token, _('API token') %> +
<%= @user.api_token %>
+ + +
<%= link_to( _('How to use the API'), controller: "token_permission_types", action: "index")%>
+
+ <% end %> + +
+ + <%= _('If you would like to change your password please complete the following fields.') %> + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+
+ + +
+
+ +
+ + <%= render partial: 'shared/accessible_submit_button', + locals: {id: 'update', + val: 'Save', + disabled_initially: true, + classes: 'small-input-button', + tooltip: _('Enter all of the required information above')} %> +
+
+ +<% end %> + + + + diff --git a/app/views/users/_notification_preferences.html.erb b/app/views/users/_notification_preferences.html.erb new file mode 100644 index 0000000..5a79ec9 --- /dev/null +++ b/app/views/users/_notification_preferences.html.erb @@ -0,0 +1,59 @@ +

<%= link_to 'Select all', '#' %> | + <%= link_to 'Deselect all', '#' %>

+<% byebug %> +
+

All Users

+
+ + + <%#= check_box_tag 'prefs[users][permission_granted]', true, @user.prefs[:users][:permission_granted] %> + <%#= label_tag 'prefs[users][permission_granted]', 'New permissions granted to me', :class => 'checkbox-label' %> +
+
+ + + <%#= check_box_tag 'prefs[users][new_comment]', true, @user.prefs[:users][:new_comment] %> + <%#= label_tag 'prefs[users][new_comment]', 'A new comment has been added to my DMP', :class => 'checkbox-label' %> +
+
+
+
+

DMP owners and co-owners

+
+ + + <%#= check_box_tag 'prefs[owners_and_coowners][visibility_changed]', true, @user.prefs[:owners_and_coowners][:visibility_changed] %> + <%#= label_tag 'prefs[owners_and_coowners][visibility_changed]', "My DMP's visibility has changed", :class => 'checkbox-label' %> +
+
+ + + <%#= check_box_tag 'prefs[owners_and_coowners][user_added]', true, @user.prefs[:owners_and_coowners][:user_added] %> + <%#= label_tag 'prefs[owners_and_coowners][user_added]', 'I have been made a co-owner of a DMP', :class => 'checkbox-label' %> +
+
+
+
+

DMP administrators

+
+ + + <%#= check_box_tag 'prefs[admins][template_published]', true, @user.prefs[:admins][:template_published] %> + <%#= label_tag 'prefs[admins][template_published]', 'An organisational template is published', :class => 'checkbox-label' %> +
+
+ + + <%#= check_box_tag 'prefs[admins][template_unpublished]', true, @user.prefs[:admins][:template_unpublished] %> + <%#= label_tag 'prefs[admins][template_unpublished]', 'An organisational template is unpublished', :class => 'checkbox-label' %> +
+
+
+
+ <%= button_to 'Save', user_update_preferences_path(@user), class: 'form-submit btn btn-primary' %> + <%= link_to 'Cancel', '#', class: 'btn btn-primary' %> +
diff --git a/config/routes.rb b/config/routes.rb index b114317..327ef69 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,6 +51,8 @@ delete '/users/identifiers/:id', to: 'user_identifiers#destroy', as: 'destroy_user_identifier' + post 'users/update_preferences/:id', to: 'user#update_preferences', as: 'user_update_preferences' + get '/orgs/shibboleth', to: 'orgs#shibboleth_ds', as: 'shibboleth_ds' post '/orgs/shibboleth', to: 'orgs#shibboleth_ds_passthru' diff --git a/db/migrate/20170606215136_add_preferences_to_users.rb b/db/migrate/20170606215136_add_preferences_to_users.rb new file mode 100644 index 0000000..f570a76 --- /dev/null +++ b/db/migrate/20170606215136_add_preferences_to_users.rb @@ -0,0 +1,10 @@ +class AddPreferencesToUsers < ActiveRecord::Migration + + def self.up + add_column :users, :prefs, :binary + end + + def self.down + remove_column :users, :prefs + end +end diff --git a/lib/assets/stylesheets/roadmap.scss b/lib/assets/stylesheets/roadmap.scss index d52d951..55d8802 100644 --- a/lib/assets/stylesheets/roadmap.scss +++ b/lib/assets/stylesheets/roadmap.scss @@ -82,3 +82,19 @@ margin-bottom: 20px; table-layout: fixed; } + + +.checkbox-label { + display: inline-block; + font-size: 1em; + margin: 0; + padding: 2px; +} + +.checkbox-input { + border: none; + vertical-align: middle; + height: 17px; + margin: 0 4px 0 0; + padding: 0; +}