-
-
Notifications
You must be signed in to change notification settings - Fork 519
[resolves 6298] Add Custom Admin-Defined Navbar Links #6350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
compwron
merged 1 commit into
rubyforgood:main
from
brodyf42:6298_add_custom_per_org_navbar_links
May 21, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| class CustomOrgLinksController < ApplicationController | ||
| before_action :set_custom_org_link, only: %i[edit update destroy] | ||
| after_action :verify_authorized | ||
|
|
||
| def new | ||
| authorize CustomOrgLink | ||
| @custom_org_link = CustomOrgLink.new | ||
| end | ||
|
|
||
| def create | ||
| authorize CustomOrgLink | ||
|
|
||
| @custom_org_link = current_organization.custom_org_links.new(custom_org_link_params) | ||
|
|
||
| if @custom_org_link.save | ||
| redirect_to edit_casa_org_path(current_organization), notice: "Custom link was successfully created." | ||
| else | ||
| render :new, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| def edit | ||
| authorize @custom_org_link | ||
| end | ||
|
|
||
| def update | ||
| authorize @custom_org_link | ||
| if @custom_org_link.update(custom_org_link_params) | ||
| redirect_to edit_casa_org_path(current_organization), notice: "Custom link was successfully updated." | ||
| else | ||
| render :edit, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| authorize @custom_org_link | ||
| @custom_org_link.destroy | ||
| redirect_to edit_casa_org_path(current_organization), notice: "Custom link was successfully deleted." | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def set_custom_org_link | ||
| @custom_org_link = CustomOrgLink.find(params[:id]) | ||
| end | ||
|
|
||
| def custom_org_link_params | ||
| params.require(:custom_org_link).permit(:text, :url, :active) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| class CustomOrgLink < ApplicationRecord | ||
| TEXT_MAX_LENGTH = 30 | ||
|
|
||
| belongs_to :casa_org | ||
| validates :text, :url, presence: true | ||
| validates :text, length: {maximum: TEXT_MAX_LENGTH} | ||
| validates :active, inclusion: {in: [true, false]} | ||
| validates :url, url: true | ||
| end | ||
|
|
||
| # == Schema Information | ||
| # | ||
| # Table name: custom_org_links | ||
| # | ||
| # id :bigint not null, primary key | ||
| # active :boolean default(TRUE), not null | ||
| # text :string not null | ||
| # url :string not null | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # casa_org_id :bigint not null | ||
| # | ||
| # Indexes | ||
| # | ||
| # index_custom_org_links_on_casa_org_id (casa_org_id) | ||
| # | ||
| # Foreign Keys | ||
| # | ||
| # fk_rails_... (casa_org_id => casa_orgs.id) | ||
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| class CustomOrgLinkPolicy < ApplicationPolicy | ||
| class Scope < ApplicationPolicy::Scope | ||
| def resolve | ||
| case user | ||
| when CasaAdmin | ||
| scope.where(casa_org: @user.casa_org) | ||
| else | ||
| scope.none | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| class UrlValidator < ActiveModel::EachValidator | ||
| InvalidSchemeError = Class.new StandardError | ||
| MissingHostError = Class.new StandardError | ||
|
|
||
| DEFAULT_SCHEMES = %w[http https].freeze | ||
|
|
||
| def validate_each(record, attribute, value) | ||
| uri = URI.parse(value) | ||
| validate_scheme uri | ||
| validate_host uri | ||
| rescue URI::InvalidURIError | ||
| record.errors.add(attribute, "format is invalid") | ||
| rescue InvalidSchemeError, MissingHostError => e | ||
| record.errors.add(attribute, e.message) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def validate_scheme(uri) | ||
| accepted_schemes = Array.wrap(options[:scheme] || DEFAULT_SCHEMES) | ||
| return if uri.scheme.in? accepted_schemes | ||
|
|
||
| raise InvalidSchemeError, "scheme invalid - only #{accepted_schemes.join(", ")} allowed" | ||
| end | ||
|
|
||
| def validate_host(uri) | ||
| raise MissingHostError, "host cannot be blank" if uri.host.blank? | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <div class="row"> | ||
| <div class="col-lg-12"> | ||
| <div class="card-style mb-30"> | ||
| <div class="row align-items-center"> | ||
| <div class="col-md-6"> | ||
| <h3>Custom Links</h3> | ||
| </div> | ||
| <div class="col-md-6"> | ||
| <div class="breadcrumb-wrapper"> | ||
| <span class="ml-5"> | ||
| <%= link_to new_custom_org_link_path, class: "btn-sm main-btn primary-btn btn-hover" do %> | ||
| <i class="lni lni-plus mr-10"></i> New Custom Link | ||
| <% end %> | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div class="table-wrapper table-responsive"> | ||
| <table class="table striped-table"> | ||
| <thead> | ||
| <tr> | ||
| <th>Display Text</th> | ||
| <th>URL</th> | ||
| <th>Active?</th> | ||
| <th>Actions</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <% if @custom_org_links.blank? %> | ||
| <tr> | ||
| <td colspan="4"> | ||
| <span class="fw-light fst-italic text-center">No custom links have been added for this organization.</span> | ||
| </td> | ||
| </tr> | ||
| <% else %> | ||
| <% @custom_org_links.each do |custom_link| %> | ||
| <tr> | ||
| <td><%= custom_link.text %></td> | ||
| <td><%= truncate(custom_link.url, length: 90) %></td> | ||
| <td><%= custom_link.active ? "Yes" : "No" %></td> | ||
| <td> | ||
| <%= link_to edit_custom_org_link_path(custom_link) do %> | ||
| <div class="action"> | ||
| <button class="text-danger"> | ||
| <i class="lni lni-pencil-alt"></i> Edit | ||
| </button> | ||
| </div> | ||
| <% end %> | ||
| <%= link_to custom_org_link_path(custom_link), method: :delete do %> | ||
| <div class="action"> | ||
| <button class="text-danger"> | ||
| <i class="lni lni-trash-can"></i> Delete | ||
| </button> | ||
| </div> | ||
| <% end %> | ||
| </td> | ||
| </tr> | ||
| <% end %> | ||
| <% end %> | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <div class="title-wrapper pt-30"> | ||
| <div class="row align-items-center"> | ||
| <div class="col-md-6"> | ||
| <div class="title mb-30"> | ||
| <h1> | ||
| <%= title %> | ||
| </h1> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div><!-- ==== end title ==== --> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comments not needed here |
||
|
|
||
| <!-- ========== card start ========== --> | ||
| <div class="card-style mb-30"> | ||
| <%= form_with model: @custom_org_link, local: true do |form| %> | ||
| <div class="alert-box danger-alert"> | ||
| <%= render "/shared/error_messages", resource: @custom_org_link %> | ||
| </div> | ||
|
|
||
| <div class="input-style-1"> | ||
| <%= form.label :name, "Display Text" %> | ||
| <%= form.text_field :text, class: "form-control", required: true %> | ||
| </div> | ||
|
|
||
| <div class="input-style-1"> | ||
| <%= form.label :name, "URL" %> | ||
| <%= form.text_field :url, class: "form-control", required: true %> | ||
| </div> | ||
|
|
||
| <div class="form-check checkbox-style mb-20"> | ||
| <%= form.check_box :active, as: :boolean, class: 'form-check-input' %> | ||
| <%= form.label :active, "Active?", class: 'form-check-label' %> | ||
| </div> | ||
|
|
||
| <div class="actions mb-10"> | ||
| <%= button_tag type: "submit", class: "btn-sm main-btn primary-btn btn-hover" do %> | ||
| <i class="lni lni-checkmark-circle mr-5"></i> <%= action %> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| <!-- card end --> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <%= render partial: "form", locals: { title: "Edit Custom Link", action: 'Update' } %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <%= render partial: "form", locals: { title: "New Custom Link", action: 'Create' } %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class CreateCustomOrgLinks < ActiveRecord::Migration[7.2] | ||
| def change | ||
| create_table :custom_org_links do |t| | ||
| t.references :casa_org, null: false, foreign_key: true | ||
| t.string :text, null: false | ||
| t.string :url, null: false | ||
| t.boolean :active, null: false, default: true | ||
| t.timestamps | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| FactoryBot.define do | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good factory :) |
||
| factory :custom_org_link do | ||
| casa_org | ||
| text { "Custom Link Text" } | ||
| url { "https://custom.link" } | ||
| active { true } | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| require "rails_helper" | ||
|
|
||
| RSpec.describe CustomOrgLink, type: :model do | ||
| it { is_expected.to belong_to :casa_org } | ||
| it { is_expected.to validate_presence_of :text } | ||
| it { is_expected.to validate_presence_of :url } | ||
| it { is_expected.to validate_length_of(:text).is_at_most described_class::TEXT_MAX_LENGTH } | ||
| it { is_expected.to validate_inclusion_of(:active).in_array [true, false] } | ||
|
|
||
| describe "url validation - only allow http or https schemes" do | ||
| it { is_expected.to allow_value("http://example.com").for(:url) } | ||
| it { is_expected.to allow_value("https://example.com").for(:url) } | ||
|
|
||
| it { is_expected.not_to allow_value("ftp://example.com").for(:url) } | ||
| it { is_expected.not_to allow_value("example.com").for(:url) } | ||
| it { is_expected.not_to allow_value("some arbitrary string").for(:url) } | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| require "rails_helper" | ||
|
|
||
| RSpec.describe CustomOrgLinkPolicy, type: :policy do | ||
| let(:casa_admin) { build_stubbed(:casa_admin) } | ||
| let(:supervisor) { build_stubbed(:supervisor) } | ||
| let(:volunteer) { build_stubbed(:volunteer) } | ||
|
|
||
| permissions :new?, :create?, :edit?, :update? do | ||
| it "permits casa_admins" do | ||
| expect(described_class).to permit(casa_admin) | ||
| end | ||
|
|
||
| it "does not permit supervisor" do | ||
| expect(described_class).not_to permit(supervisor) | ||
| end | ||
|
|
||
| it "does not permit volunteer" do | ||
| expect(described_class).not_to permit(volunteer) | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good policy