initial commit

This commit is contained in:
2018-01-20 13:02:44 -03:00
commit 203138a969
650 changed files with 19523 additions and 0 deletions
@@ -0,0 +1,27 @@
module Dunlop
class ApplicationController < ::ApplicationController
layout 'application'
before_action :store_or_reset_params_q, only: :index
private
def query
params[:q]
end
def store_or_reset_params_q
session_key = "#{controller_path}_q"
session[session_key] = nil if params[:reset_q].present?
params[:q] = session[session_key] if params[:q].blank?
current_query = (params[:q] || {}).select{|k,v | v.present? }
session[session_key] = current_query if params[:q].present?
end
if Rails::VERSION::MAJOR < 5
def redirect_back(fallback_location:, **args)
redirect_to :back, args
end
end
end
end
@@ -0,0 +1,72 @@
class Dunlop::DashboardController < Dunlop::ApplicationController
def home
end
def badge_info
@process_class = params[:resource].to_s.classify.safe_constantize
return head(:not_found) unless @process_class.present?
if params[:id].present?
setup_badge_info_for_record
else
if @process_class.ancestors.include?(WorkflowInstance)
setup_badge_info_for_scenario
else
setup_badge_info_for_subprocess
end
end
render layout: false
end
def changelog
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
changelog_path = Rails.root.join('CHANGELOG.md')
render text: "No changelog present" unless File.exist?(changelog_path)
source = File.read(changelog_path)
source.gsub!(/(?<!\\)_/, '\_') # underscores are preserved
html = markdown.render source
html = "<div class='ui container'>#{html}</div>"
render html: html.html_safe, layout: true
end
# POST /archived_mode
def archived_mode
session[:archived_mode] = true
redirect_to main_app.root_path
end
# POST /active_mode
def active_mode
session[:archived_mode] = false
redirect_to main_app.root_path
end
private
def workflow_instances_scope(scope_options = {})
scope_options[:archived] = session[:archived_mode] if can?(:archive, @record_class) and not scope_options[:all].present?
@record_class.scope_for(current_user, scope_options)
end
def setup_badge_info_for_record
@record = @process_class.find(params[:id])
authorize! :read, @record
end
def setup_badge_info_for_scenario
@record_class = @process_class
@record_batch_class = @record_class.batch_class
@workflow_instances = workflow_instances_scope.where(state: params[:state])
end
def setup_badge_info_for_subprocess
# @process_class is a subprocess, so only show workflow_instances
# belonging to this subprocess
@record_class = WorkflowInstance # no type preference, depends on subprocess
@workflow_instances = workflow_instances_scope.joins(@process_class.process_name.to_sym).where(@process_class.table_name => {sti_type: @process_class.name, state: params[:state]})
if params[:workflow_instance_batch_id].present?
# Limit query for to specific batch
@workflow_instance_batch = WorkflowInstanceBatch.find(params[:workflow_instance_batch_id])
@workflow_instances = @workflow_instances.where(workflow_instance_batch_id: @workflow_instance_batch.id)
end
end
end
@@ -0,0 +1,18 @@
class Dunlop::ExecutionBatchesController < Dunlop::ApplicationController
respond_to :html
def index
authorize! :index, ExecutionBatch
@q = ExecutionBatch.search(query)
@q.sorts = 'created_at desc' if @q.sorts.empty?
@batches = @q.result.page(params[:page])
respond_with(@batches)
end
def show
@record = ExecutionBatch.find(params[:id])
authorize! :show, @record
respond_with(@record)
end
end
+3
View File
@@ -0,0 +1,3 @@
module Dunlop::Reports
end
@@ -0,0 +1,25 @@
class Dunlop::Reports::SystemController < Dunlop::ApplicationController
def index
authorize! :report, :index
end
def workflow_instance_fields
authorize! :report, :system
end
def workflow_instance_workflow_steps
authorize! :report, :system
end
def workflow_step_scenarios
authorize! :report, :system
end
def workflow_steps_in_batch_finished
authorize! :report, :system
end
def workflow_steps_overdue
authorize! :report, :system
end
end
@@ -0,0 +1,63 @@
class Dunlop::SourceFilesController < Dunlop::ApplicationController
respond_to :html
def index
authorize! :index, SourceFile
@q = SourceFile.where(sti_type: SourceFile.classes.select{|cls| can? :read, cls}.map(&:name)).search(query)
@q.sorts = "created_at desc" if @q.sorts.empty?
@source_files = @q.result.page(params[:page]).per(100)
respond_with(@source_files)
end
def show
@source_file = SourceFile.find(params[:id])
authorize! :read, @source_file
respond_with(@source_file)
end
def new
@source_file = SourceFile.new
authorize! :manage, @source_file
respond_with(@source_file)
end
def create
@source_file = SourceFile.factory(source_file_params)
redirect_to source_files_path, alert: "No file given" and return unless params[:source_file][:original_file].present?
redirect_to source_files_path, alert: "No type specified" and return unless params[:source_file][:sti_type].present?
authorize! :manage, @source_file
@source_file.creator = current_user
@source_file.save && @source_file.autoload!
redirect_to source_files_path
end
def destroy
@source_file = SourceFile.find(params[:id])
authorize! :manage, @source_file
@source_file.destroy
redirect_to source_files_path
end
def download
@source_file = SourceFile.find(params[:id])
authorize! :download, @source_file
return redirect_back(fallback_location: source_files_path, alert: "File is no longer present") unless @source_file.original_file.present?
Dunlop::FileDownload.create user: current_user, file: @source_file
send_file @source_file.original_file.path
end
def schedule
@source_file = SourceFile.find(params[:id])
authorize! :manage, @source_file
@source_file.scheduled!
flash[:notice] = "Successfully scheduled loading of source file"
redirect_to source_files_path
end
private
def source_file_params
params.require(:source_file).permit(:sti_type, :original_file)
end
end
@@ -0,0 +1,43 @@
class Dunlop::TargetFilesController < Dunlop::ApplicationController
skip_authorize_resource if respond_to?(:skip_authorize_resource)
before_action :find_target_file, except: [:index, :download_latest]
def index
authorize! :index, TargetFile
@q = TargetFile.where(sti_type: TargetFile.classes.select{|cls| can? :read, cls}.map(&:name)).search(query)
@q.sorts = "created_at desc" if @q.sorts.empty?
@target_files = @q.result.page(params[:page]).per(100)
end
def show
authorize! :read, @target_file
end
def download
authorize! :download, @target_file
Dunlop::FileDownload.create user: current_user, file: @target_file
send_file @target_file.original_file.path
end
def download_latest
target_file_class = "TargetFile::#{params[:target_file_type].to_s.camelize}".safe_constantize
@target_file = target_file_class.latest
return head(:not_found) unless @target_file.present?
authorize! :download, @target_file
Dunlop::FileDownload.create user: current_user, file: @target_file
send_file @target_file.original_file.path
end
def destroy
authorize! :destroy, @target_file
@target_file.destroy
redirect_to dunlop.target_files_path, notice: t('action.destroy.successfull', model: @target_file.class.model_name.human)
end
private
def find_target_file
@target_file = TargetFile.find(params[:id])
end
end
+125
View File
@@ -0,0 +1,125 @@
class Dunlop::UsersController < Dunlop::ApplicationController
skip_authorize_resource if respond_to?(:skip_authorize_resource)
skip_authorization_check if respond_to?(:skip_authorization_check)
respond_to :html
before_action :find_record, only: %i[show edit update destroy]
before_action :set_current_user_as_user, only: %i[profile edit_profile update_profile]
before_action :log_current_user, on: [:create, :update, :destroy, :become_user]
def profile
end
def edit_profile
end
def update_profile
user_params = params.require(:user).permit(:password, :confirmation_password)
if @user.update_attributes(user_params)
sign_in @user, bypass_sign_in: true
redirect_to dunlop.profile_users_path
else
render action: :edit_profile
end
end
def index
authorize! :index, User
@users = User.active.page(params[:page])
end
def new
@user = User.new
authorize! :create, @user
end
def create
@user = User.new user_params
authorize! :create, @user
if @user.save
redirect_to dunlop.users_path
else
render action: :edit
end
end
def show
authorize! :show, @user
end
def edit
authorize! :update, @user
end
def update
authorize! :update, @user
if user_params[:password].blank?
@user.update_without_password(user_params)
else
@user.update_attributes(user_params)
end
if @user.errors.present?
render action: :edit
else
redirect_to dunlop.users_path
end
end
def become_user
@user = User.find(params[:id])
authorize! :become_user, @user
raise CanCan::AccessDenied if @user.admin? and not current_user.admin? # Do not allow non admin users with user management authorization to become an admin user
sign_in @user, bypass_sign_in: true
respond_with(@user, location: user_path)
end
def destroy
authorize! :destroy, @user
@user.destroy
redirect_to dunlop.users_path
end
def permissions_table
authorize! :permissions_table, User
@table = Hash.new{|h,k| h[k] = Hash.new{|h2, k2| h2[k2] = []} }
@users = User.active
@users.each do |user|
user.role_names.each do |role|
if match = role.match(/(^[a-z0-9]+)-class-(.*)/)
role_class = match[2].safe_constantize
if role_class.respond_to?(:model_name)
role = role_class.model_name.human
else
role = role_class.try(:name)
end
@table[role][user] << match[1]
else
@table[role][user] << "check"
end
end
end
end
private
def find_record
@user = User.find(params[:id])
end
def set_current_user_as_user
@user = current_user
end
def user_params
permitted_params = [:ruisnaam, :email, :password, :password_confirmation, {role_names: []}]
if current_user.admin?
permitted_params.push(:admin, role_names_admin: [])
end
params.require(:user).permit(*permitted_params)
end
def log_current_user
logger.info "#{current_user.try(:email)} having id #{current_user.try(:id)} did user change"
end
end
@@ -0,0 +1,54 @@
class Dunlop::WorkflowInstancesController < Dunlop::ApplicationController
respond_to :html, :csv
def reset
authorize! :reset, WorkflowInstance
@records = WorkflowInstance.find ids_param
@records.each(&:reset!)
redirect_path = @records.size == 1 ? [main_app, @records.first] : polymorphic_path([main_app, :selection, @records.first.try(:class) || WorkflowInstance], ids: ids_param.join(RecordCollection.ids_separator))
redirect_back(fallback_location: redirect_path)
end
def categorize_as
scenario_name = params[:scenario].to_s
target_scenario_class = "WorkflowInstance::#{scenario_name.classify}".safe_constantize
authorize! :categorize, target_scenario_class # general target authorization
@records = WorkflowInstance.find ids_param
@records.select{|r| can? :categorize, r }.each { |record| record.categorize_as scenario_name } # individual from authorization
redirect_path = polymorphic_path([main_app, :selection, target_scenario_class], ids: ids_param.join(RecordCollection.ids_separator))
respond_to do |format|
format.js { render js: "window.location = '#{redirect_path}'" }
format.html { redirect_to redirect_path }
end
end
# POST /dunlop/workflow_instances/archive?ids=1~2~3~....
def archive
authorize! :archive, WorkflowInstance
WorkflowInstance.where(id: ids_param).archive!
session[:archived_mode] = true
if ids_param and ids_param.size == 1
redirect_to [main_app, WorkflowInstance.find_by(id: ids_param.first)]
else
redirect_to main_app.root_path
end
end
# POST /dunlop/workflow_instances/revive?ids=1~2~3~....
def revive
authorize! :archive, WorkflowInstance
WorkflowInstance.where(id: ids_param).revive!
session[:archived_mode] = false
if ids_param and ids_param.size == 1
redirect_to [main_app, WorkflowInstance.find_by(id: ids_param.first)]
else
redirect_to main_app.root_path
end
end
private
def find_record
@record = WorkflowInstance.find(params[:id])
end
end