forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Links must be https. Add validate_url ruby gem to validate the urls. Add not null on link site and url. Add relevant FK.
- Loading branch information
Showing
20 changed files
with
492 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -9,10 +9,4 @@ | |
label { | ||
font-weight: bold; | ||
} | ||
ul { | ||
display: inline-block; | ||
} | ||
ul > li { | ||
display: inline-block; | ||
} | ||
} |
This file contains 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,61 @@ | ||
class CommunityLinksController < ApplicationController | ||
layout "site" | ||
before_action :authorize_web | ||
|
||
before_action :set_link, :only => [:destroy, :edit, :update] | ||
|
||
load_and_authorize_resource :except => [:create, :new] | ||
authorize_resource | ||
|
||
def index | ||
@community = Community.friendly.find(params[:community_id]) | ||
@links = @community.community_links | ||
end | ||
|
||
def new | ||
return "missing parameter community_id" unless params.key?(:community_id) | ||
|
||
@community = Community.friendly.find(params[:community_id]) | ||
@title = t ".title" | ||
@link = CommunityLink.new | ||
@link.community_id = params[:community_id] | ||
end | ||
|
||
def edit; end | ||
|
||
def create | ||
@community = Community.friendly.find(params[:community_id]) | ||
@link = @community.community_links.build(link_params) | ||
if @link.save | ||
response.set_header("link_id", @link.id) # for testing | ||
redirect_to @link.community, :notice => t(".success") | ||
else | ||
render "new" | ||
end | ||
end | ||
|
||
def update | ||
if @link.update(link_params) | ||
redirect_to @link.community, :notice => t(".success") | ||
else | ||
flash.now[:alert] = t(".failure") | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
community_id = @link.community_id | ||
@link.delete | ||
redirect_to community_path(community_id) | ||
end | ||
|
||
private | ||
|
||
def set_link | ||
@link = CommunityLink.find(params[:id]) | ||
end | ||
|
||
def link_params | ||
params.require(:community_link).permit(:community_id, :site, :url) | ||
end | ||
end |
This file contains 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 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,25 @@ | ||
# == Schema Information | ||
# | ||
# Table name: community_links | ||
# | ||
# id :bigint(8) not null, primary key | ||
# community_id :bigint(8) not null | ||
# site :string not null | ||
# url :string not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# Indexes | ||
# | ||
# index_community_links_on_community_id (community_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (community_id => communities.id) | ||
# | ||
|
||
class CommunityLink < ApplicationRecord | ||
belongs_to :community | ||
validates :site, :presence => true, :length => 1..255, :characters => true | ||
validates :url, :presence => true, :length => 1..255, :url => { :schemes => ["https"] } | ||
end |
This file contains 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 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,5 @@ | ||
<%= bootstrap_form_for [@community, @link] do |form| %> | ||
<%= form.text_field :site %> | ||
<%= form.text_field :url %> | ||
<%= form.primary %> | ||
<% end %> |
This file contains 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,3 @@ | ||
<h1><%= t(".edit_community_link") %></h1> | ||
|
||
<%= render "form", :link => @link %> |
This file contains 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,27 @@ | ||
<% content_for :heading do %> | ||
<h1><%= t(".title") %></h1> | ||
<nav class="secondary-actions"> | ||
<ul class='clearfix'> | ||
<li><%= link_to image_tag("new.png", :class => "small_icon", :border => 0) + t(".new"), new_community_community_link_path(@community) %></li> | ||
</ul> | ||
</nav> | ||
<% end %> | ||
<% if !@links.empty? %> | ||
<table class="table table-borderless table-striped"> | ||
<tbody> | ||
<% @links.each do |link| %> | ||
<tr> | ||
<td> | ||
<% link.url.slice! "https://" %> <%# prevent XSS %> | ||
<%= link_to link.site, "https://#{link.url}" %> | ||
</td> | ||
<td> | ||
<%= link_to t(".edit"), edit_community_link_path(link) %> | ||
<%= link_to t(".delete"), community_link_path(link), :method => :delete %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> |
This file contains 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,5 @@ | ||
<% content_for :heading do %> | ||
<h1><%= @title %></h1> | ||
<% end %> | ||
<%= render "form", :link => @link %> |
This file contains 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 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 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 CreateCommunityLinks < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :community_links do |t| | ||
t.references :community, :null => false, :foreign_key => true, :index => true | ||
t.string :site, :null => false | ||
t.string :url, :null => false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Oops, something went wrong.