Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.3 KiB
Ruby
46 lines
1.3 KiB
Ruby
class ProjectsController < ApplicationController
|
|
before_action :require_admin
|
|
before_action :set_project, only: %i[edit update destroy]
|
|
skip_before_action :set_current_project, only: %i[create], raise: false
|
|
|
|
def create
|
|
@project = Project.new(project_params)
|
|
if @project.save
|
|
redirect_to settings_path(project_code: @project.code), notice: "Progetto creato. Sei nell'istanza #{@project.name}."
|
|
else
|
|
redirect_to root_path(new_project: 1), alert: @project.errors.full_messages.to_sentence
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@page_title = "Modifica progetto"
|
|
end
|
|
|
|
def update
|
|
if @project.update(project_params)
|
|
redirect_to(current_project ? settings_path : root_path, notice: "Progetto aggiornato.")
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
if @project.opportunities.exists?
|
|
redirect_to(current_project ? settings_path : root_path, alert: "Impossibile eliminare: ci sono opportunità collegate.")
|
|
else
|
|
@project.destroy!
|
|
redirect_to root_path, notice: "Progetto eliminato."
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_project
|
|
@project = Project.find(params[:id])
|
|
end
|
|
|
|
def project_params
|
|
params.require(:project).permit(:name, :code, :description, :active, :position, :color)
|
|
end
|
|
end
|