Skip to content

Commit

Permalink
Merge pull request #83 from NEU-DSG/pr-party
Browse files Browse the repository at this point in the history
PR party: another!
  • Loading branch information
candyhazlett authored Mar 6, 2023
2 parents ded020f + 1d4df8f commit 618e687
Show file tree
Hide file tree
Showing 22 changed files with 290 additions and 76 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ end

gem "devise"
gem "devise-guests", "~> 0.3"
gem 'devise_invitable', '~> 2.0.0'
gem "cancancan"

gem "rsolr"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ GEM
warden (~> 1.2.3)
devise-guests (0.7.0)
devise
devise_invitable (2.0.2)
actionmailer (>= 5.0)
devise (>= 4.6)
diff-lcs (1.3)
discard (1.2.0)
activerecord (>= 4.2, < 7)
Expand Down Expand Up @@ -624,6 +627,7 @@ DEPENDENCIES
coffee-rails (~> 5.0.0)
devise
devise-guests (~> 0.3)
devise_invitable (~> 2.0.0)
discard (~> 1.2)
exception_notification
factory_bot_rails
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding : utf-8 -*-
require 'blacklight/catalog'

class CatalogController < ApplicationController
include Blacklight::Catalog
include Hydra::Controller::ControllerBehavior
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ def upsert

def index
@page_title = "All Collections"
# self.search_params_logic += [:collections_filter]
# self.search_params_logic += [:add_access_controls_to_solr_params]
(@response, @document_list) = search_results(params) #, search_params_logic)
@results = Collection.order(updated_at: :desc)

respond_to do |format|
format.html { render :template => 'shared/index' }
format.js { render :template => 'shared/index', :layout => false }
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/communities_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class CommunitiesController < CatalogController
class CommunitiesController < ApplicationController
include ApiAccessible

self.copy_blacklight_config_from(CatalogController)

before_action :can_edit?, only: [:edit, :update, :destroy]
before_action :can_read?, :only => :show
# before_action :enforce_show_permissions, :only=>:index
Expand All @@ -23,7 +21,7 @@ def upsert
def index
@page_title = "All Projects"

(@response, @document_list) = search_results(params)
@results = Community.all

respond_to do |format|
format.html { render :template => 'shared/index' }
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/core_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class CoreFilesController < CatalogController

def index
@page_title = "All CoreFiles"
# self.search_params_logic += [:core_files_filter]
(@response, @document_list) = search_results(params) #, search_params_logic)
@results = CoreFile.order(updated_at: :desc)

respond_to do |format|
format.html { render :template => 'shared/index' }
format.js { render :template => 'shared/index', :layout => false }
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/users/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Users::InvitationsController < Devise::InvitationsController
before_action :verify_admin

protected

def verify_admin
!current_user.admin_at.nil?
end
end
72 changes: 19 additions & 53 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class UsersController < CatalogController

self.copy_blacklight_config_from(CatalogController)
before_action :check_for_logged_in_user, :only => [:my_tapas, :my_projects]
before_action :verify_admin, :only => [:index, :show, :create, :delete]
before_action :verify_admin, :only => [:index, :show, :create, :delete, :admin_show]

def my_tapas
@page_title = "My TAPAS"
Expand All @@ -16,24 +16,22 @@ def my_tapas
def my_projects
@page_title = "My Projects"
@user = current_user
@projects = @user.communities
@results = @user.communities

render 'my_projects'
end

def my_collections
@page_title = "My Collections"
@user = current_user
# self.search_params_logic += [:my_collections_filter]
(@collections, @document_list) = search_results(params) #, search_params_logic)
@results = Collection.kept.accessible_by(current_ability)
render 'my_collections'
end

def my_records
@page_title = "My Records"
@user = current_user
# self.search_params_logic += [:my_records_filter]
(@records, @document_list) = search_results(params) #, search_params_logic)
@results = CoreFile.kept.accessible_by(current_ability)
render 'my_records'
end

Expand All @@ -60,22 +58,15 @@ def profile

def edit
@user = User.find(params[:id])
i_s = Institution.all()
@institutions = []
i_s.each do |i|
@institutions << [i.name, i.id]
end
@institutions = Institution.select(:name, :id)
end

def update
@user = User.find(params[:id])
@user.name = params[:user][:name]
@user.email = params[:user][:email]
@user.role = params[:user][:role]
@user.account_type = params[:user][:account_type]
@user.institution = Institution.find(params[:user][:institution_id])
@user.save!
redirect_to @user
@user.update(user_params)
flash[:notice] = "#{@user.email} was updated"

redirect_to edit_user_path(@user)
end

def destroy
Expand Down Expand Up @@ -112,7 +103,16 @@ def mail_all_users
end
end

private
def user_params
params.require(:user).permit(
:name,
:email,
:institution_id,
:account_type,
:admin,
:paid
)
end

def five_communities
@user.communities.kept.limit(5).order("RAND()")
Expand All @@ -134,40 +134,6 @@ def five_records
.order("RAND()")
end

def my_communities_filter(solr_parameters, user_parameters)
model_type = RSolr.solr_escape "info:fedora/afmodel:Community"
query = "has_model_ssim:\"#{model_type}\" && (project_members_ssim:\"#{@user.id.to_s}\" OR depositor_tesim:\"#{@user.id.to_s}\" OR project_admins_ssim:\"#{@user.id.to_s}\" OR project_editors_ssim:\"#{@user.id.to_s}\")"
logger.error query
solr_parameters[:fq] ||= []
solr_parameters[:fq] << query
end

def my_collections_filter(solr_parameters, user_parameters)
model_type = RSolr.solr_escape "info:fedora/afmodel:Collection"
projects = ActiveFedora::SolrService.query("has_model_ssim:\"#{RSolr.solr_escape "info:fedora/afmodel:Community"}\" && (project_members_ssim:\"#{@user.id.to_s}\" OR depositor_tesim:\"#{@user.id.to_s}\" OR project_admins_ssim:\"#{@user.id.to_s}\" OR project_editors_ssim:\"#{@user.id.to_s}\")")
col_query = projects.map do |p|
"project_pid_ssi: #{RSolr.solr_escape(p['id'])}"
end
solr_parameters[:fq] ||= []
solr_parameters[:fq] << col_query.join(" OR ")
solr_parameters[:fq] << "has_model_ssim: \"#{model_type}\""
end

def my_records_filter(solr_parameters, user_parameters)
model_type = RSolr.solr_escape "info:fedora/afmodel:CoreFile"
projects = ActiveFedora::SolrService.query("has_model_ssim:\"#{RSolr.solr_escape "info:fedora/afmodel:Community"}\" && (project_members_ssim:\"#{@user.id.to_s}\" OR depositor_tesim:\"#{@user.id.to_s}\" OR project_admins_ssim:\"#{@user.id.to_s}\" OR project_editors_ssim:\"#{@user.id.to_s}\")")
col_query = projects.map do |p|
"project_pid_ssi: #{RSolr.solr_escape(p['id'])}"
end
collections = ActiveFedora::SolrService.query("has_model_ssim:\"#{RSolr.solr_escape "info:fedora/afmodel:Collection"}\" && (#{col_query.join(" OR ")})")
rec_query = collections.map do |y|
"collections_pids_ssim: \"#{RSolr.solr_escape(y['id'])}\""
end
solr_parameters[:fq] ||= []
solr_parameters[:fq] << rec_query.join(" OR ")
solr_parameters[:fq] << "has_model_ssim: \"#{model_type}\""
end

def check_for_logged_in_user
redirect_to new_user_session_path if current_user.nil?
end
Expand Down
18 changes: 17 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class User < ActiveRecord::Base

# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable

delegate :can?, :cannot?, :to => :ability
Expand Down Expand Up @@ -49,10 +49,26 @@ def user_key
self.id.to_s
end

def admin=(n)
if n.to_i == 0
update(admin_at: nil)
else
update(admin_at: Time.zone.now)
end
end

def admin?
!admin_at.nil?
end

def paid=(n)
if n.to_i == 0
update(paid_at: nil)
else
update(paid_at: Time.zone.now)
end
end

def paid_user?
!paid_at.nil?
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

%h3
= "Users"
=link_to "Create New User", new_user_registration_path, class:['btn', 'btn-primary', 'btn-large']
=link_to "Create New User", new_user_invitation_path, class:['btn', 'btn-primary', 'btn-large']
%br
=link_to "View all Users", users_path, class:['btn', 'btn-primary', 'btn-large']
%br
Expand Down
1 change: 1 addition & 0 deletions app/views/catalog/_facets.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
</div>

<div id="facet-panel-collapse" class="collapse panel-group">

</div>
</div>
49 changes: 46 additions & 3 deletions app/views/catalog/_search_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,49 @@
<%= render 'catalog/search_header' %>

<h2 class="sr-only"><%= t('blacklight.search.search_results') %></h2>
<%- if @response.empty? %>
<%= render "zero_results" %>
<%- end %>

<table class="table table-striped">
<tr>
<th>Title</th>
<th>Description</th>
<th>Depositor</th>
<th>Actions</th>
</tr>
<%- @results.map do |r| %>
<tr>
<td>
<%= r.title %>
</td>
<td>
<%= r.description %>
</td>
<td>
<%= r.depositor.nil? ? "No depositor on file" : r.depositor.email %>
</td>
<td>
<%- if can? :manage, r %>
<a class="btn btn-default btn-sm"
href="<%= url_for(
only_path: true,
controller: request.path
.sub('my_', '')
.sub('records', 'core_files')
.sub('projects', 'communities'),
action: 'edit',
id: r.id) %>">Edit</a>
<a class="btn btn-danger btn-sm"
href="<%= url_for(
only_path: true,
controller: request.path
.sub('my_', '')
.sub('records', 'core_files')
.sub('projects', 'communities'),
action: 'destroy',
id: r.id) %>"
data-method="delete"
data-confirm="Are you sure you want to delete this <%= r.class.to_s %>?">Delete</a>
<% end %>
</td>
</tr>
<% end %>
</table>
14 changes: 9 additions & 5 deletions app/views/users/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@
.col-md-6
= f.text_field :email, required: true, class: "form-control", placeholder: "Email"
.form-group
= f.label :institution, "Institution", class: "control-label col-md-2"
= f.label :institution_id, "Institution", class: "control-label col-md-2"
.col-md-6
= f.collection_select(:institution_id, Institution.all, :id, :name, :prompt => 'Please select institution')
= f.select :institution_id, options_for_select(@institutions.map { |i| [i.name, i.id] }, @user.institution_id), required: true, include_blank: true
.form-group
= f.label :account_type, "Account Type", class: "control-label col-md-2"
.col-md-6
= f.select :account_type, options_for_select([['Free Account', 'free'], ['TEI-C Member Account', 'teic'], ['TEI-C Member via my institution', 'teic_inst']], @user.account_type), {}
- if current_user.admin?
.form-group
= f.label :role, "Admin", class: "control-label col-md-2"
= f.label :admin, "Admin?", class: "control-label col-md-2"
.col-md-6
.checkbox
= f.select :role, options_for_select([['Admin', 'admin'], ['Unpaid User', 'unpaid_user'], ['Paid User', 'paid_user']], @user.role), {}

= f.check_box :admin, {:checked => [email protected]_at.nil?}
.form-group
= f.label :paid, "Paid?", class: "control-label col-md-2"
.col-md-6
.checkbox
= f.check_box :paid, {:checked => [email protected]_at.nil?}
%hr
.form-actions
= f.submit class: ['btn', 'btn-primary', 'btn-large'], value: 'Submit'
15 changes: 15 additions & 0 deletions app/views/users/invitations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h2><%= t "devise.invitations.edit.header" %></h2>

<%= simple_form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>
<%= f.hidden_field :invitation_token %>

<div class="form-inputs">
<%= f.input :password %>
<%= f.input :password_confirmation %>
</div>

<div class="form-actions">
<%= f.button :submit, t("devise.invitations.edit.submit_button") %>
</div>
<% end %>
19 changes: 19 additions & 0 deletions app/views/users/invitations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h2><%= t "devise.invitations.new.header" %></h2>

<%= simple_form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>

<div class="form-inputs">
<%= f.input :name, required: true %>
</div>

<% resource.class.invite_key_fields.each do |field| -%>
<div class="form-inputs">
<%= f.input field, required: true %>
</div>
<% end -%>

<div class="form-actions">
<%= f.button :submit, t("devise.invitations.new.submit_button") %>
</div>
<% end %>
11 changes: 11 additions & 0 deletions app/views/users/mailer/invitation_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p><%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %></p>

<p><%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %></p>

<p><%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token) %></p>

<% if @resource.invitation_due_at %>
<p><%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) %></p>
<% end %>

<p><%= t("devise.mailer.invitation_instructions.ignore") %></p>
Loading

0 comments on commit 618e687

Please sign in to comment.