Commit iniziale di eminuxCRM: CRM Rails con pipeline, campagne email e Docker.
Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
module Authentication
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_action :require_login
|
||||
helper_method :current_user, :logged_in?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_user
|
||||
@current_user ||= session[:user_id] ? User.find_by(id: session[:user_id]) : nil
|
||||
end
|
||||
|
||||
def logged_in?
|
||||
current_user.present? && current_user.active?
|
||||
end
|
||||
|
||||
def require_login
|
||||
if current_user.present? && !current_user.active?
|
||||
logout
|
||||
redirect_to login_path, alert: "Il tuo account è stato disabilitato."
|
||||
return
|
||||
end
|
||||
return if logged_in?
|
||||
|
||||
redirect_to login_path, alert: "Effettua l'accesso per continuare."
|
||||
end
|
||||
|
||||
def require_admin
|
||||
return if current_user&.admin? && current_user.active?
|
||||
|
||||
redirect_to root_path, alert: "Accesso riservato agli amministratori."
|
||||
end
|
||||
|
||||
def login_as(user)
|
||||
reset_session
|
||||
session[:user_id] = user.id
|
||||
@current_user = user
|
||||
Current.user = user
|
||||
end
|
||||
|
||||
def logout
|
||||
reset_session
|
||||
@current_user = nil
|
||||
Current.user = nil
|
||||
end
|
||||
|
||||
def set_current_user
|
||||
Current.user = current_user
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,73 @@
|
||||
module ProjectScoping
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
helper_method :current_project, :available_projects, :in_project_space?
|
||||
before_action :set_current_project, if: :logged_in?
|
||||
end
|
||||
|
||||
def default_url_options
|
||||
return {} unless respond_to?(:request) && request&.path&.start_with?("/p/") && current_project
|
||||
|
||||
{ project_code: current_project.code }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def available_projects
|
||||
@available_projects ||= if current_user&.admin?
|
||||
Project.active.ordered
|
||||
elsif current_user
|
||||
current_user.accessible_projects
|
||||
else
|
||||
Project.none
|
||||
end
|
||||
end
|
||||
|
||||
def current_project
|
||||
Current.project
|
||||
end
|
||||
|
||||
def in_project_space?
|
||||
current_project.present? && request.path.start_with?("/p/")
|
||||
end
|
||||
|
||||
def set_current_project
|
||||
code = params[:project_code].to_s.presence
|
||||
unless code
|
||||
Current.project = nil
|
||||
return
|
||||
end
|
||||
|
||||
project = available_projects.find_by(code: code)
|
||||
if project.nil?
|
||||
redirect_to root_path, alert: "Non hai accesso a questo progetto."
|
||||
return
|
||||
end
|
||||
|
||||
Current.project = project
|
||||
session[:last_project_code] = project.code
|
||||
end
|
||||
|
||||
def require_current_project!
|
||||
return if current_project
|
||||
|
||||
redirect_to root_path, alert: "Seleziona un progetto per continuare."
|
||||
end
|
||||
|
||||
def organizations_for_current_project
|
||||
Organization.for_project(current_project)
|
||||
end
|
||||
|
||||
def opportunities_for_current_project
|
||||
Opportunity.for_project(current_project)
|
||||
end
|
||||
|
||||
def tasks_for_current_project
|
||||
Task.for_project(current_project)
|
||||
end
|
||||
|
||||
def project_home_path_for(project)
|
||||
project_root_path(project_code: project.code)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user