|
| 1 | +class CustomOrgLinksController < ApplicationController |
| 2 | + before_action :set_custom_org_link, only: %i[edit update destroy] |
| 3 | + after_action :verify_authorized |
| 4 | + |
| 5 | + def new |
| 6 | + authorize CustomOrgLink |
| 7 | + @custom_org_link = CustomOrgLink.new |
| 8 | + end |
| 9 | + |
| 10 | + def create |
| 11 | + authorize CustomOrgLink |
| 12 | + |
| 13 | + if current_organization.custom_org_links.count >= CustomOrgLink::MAX_RECORDS_PER_ORG |
| 14 | + return redirect_to edit_casa_org_path(current_organization), alert: "Custom Link was not created - limit has been reached." |
| 15 | + end |
| 16 | + |
| 17 | + @custom_org_link = current_organization.custom_org_links.new(custom_org_link_params) |
| 18 | + |
| 19 | + if @custom_org_link.save |
| 20 | + redirect_to edit_casa_org_path(current_organization), notice: "Custom link was successfully created." |
| 21 | + else |
| 22 | + render :new, status: :unprocessable_entity |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + def edit |
| 27 | + authorize @custom_org_link |
| 28 | + end |
| 29 | + |
| 30 | + def update |
| 31 | + authorize @custom_org_link |
| 32 | + if @custom_org_link.update(custom_org_link_params) |
| 33 | + redirect_to edit_casa_org_path(current_organization), notice: "Custom link was successfully updated." |
| 34 | + else |
| 35 | + render :edit, status: :unprocessable_entity |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + def destroy |
| 40 | + authorize @custom_org_link |
| 41 | + @custom_org_link.destroy |
| 42 | + redirect_to edit_casa_org_path(current_organization), notice: "Custom link was successfully deleted." |
| 43 | + end |
| 44 | + |
| 45 | + private |
| 46 | + |
| 47 | + def set_custom_org_link |
| 48 | + @custom_org_link = CustomOrgLink.find(params[:id]) |
| 49 | + end |
| 50 | + |
| 51 | + def custom_org_link_params |
| 52 | + params.require(:custom_org_link).permit(:text, :url, :active) |
| 53 | + end |
| 54 | +end |
0 commit comments