Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
1.7 KiB
Ruby
74 lines
1.7 KiB
Ruby
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
|