Edit domain names, updates credentials and virtuals Model domain tests for length and valid characters
84 lines
2.2 KiB
Ruby
84 lines
2.2 KiB
Ruby
class DomainsController < ApplicationController
|
|
before_action :set_domain, only: %i[ show edit update destroy ]
|
|
|
|
# GET /domains or /domains.json
|
|
def index
|
|
@domains = Domain.all
|
|
end
|
|
|
|
# GET /domains/1 or /domains/1.json
|
|
def show
|
|
end
|
|
|
|
# GET /domains/new
|
|
def new
|
|
@domain = Domain.new
|
|
end
|
|
|
|
# GET /domains/1/edit
|
|
def edit
|
|
end
|
|
|
|
# POST /domains or /domains.json
|
|
def create
|
|
@domain = Domain.new(domain_params)
|
|
|
|
respond_to do |format|
|
|
if @domain.save
|
|
format.html { redirect_to domain_url(@domain), notice: "Domain was successfully created." }
|
|
format.json { render :show, status: :created, location: @domain }
|
|
else
|
|
format.html { render :new, status: :unprocessable_entity }
|
|
format.json { render json: @domain.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /domains/1 or /domains/1.json
|
|
def update
|
|
pre_domain_name = @domain.domain
|
|
respond_to do |format|
|
|
if @domain.update(domain_params)
|
|
# now we need to update the credentials and virtuals
|
|
|
|
@domain.credentials.each do |credential|
|
|
credential.email.sub! pre_domain_name, @domain.domain
|
|
credential.save
|
|
end
|
|
|
|
@domain.virtuals.each do |virtual|
|
|
virtual.email.sub! pre_domain_name, @domain.domain
|
|
virtual.save
|
|
end
|
|
|
|
format.html { redirect_to domain_url(@domain), notice: "Domain was successfully updated." }
|
|
format.json { render :show, status: :ok, location: @domain }
|
|
else
|
|
format.html { render :edit, status: :unprocessable_entity }
|
|
format.json { render json: @domain.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /domains/1 or /domains/1.json
|
|
def destroy
|
|
@domain.destroy
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to domains_url, notice: "Domain was successfully destroyed." }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
private
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_domain
|
|
@domain = Domain.find(params[:id])
|
|
end
|
|
|
|
# Only allow a list of trusted parameters through.
|
|
def domain_params
|
|
params.require(:domain).permit(:domain)
|
|
end
|
|
end
|