FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow projects to be blacklisted for tips. by admtnnr · Pull Request #163 · tip4commit/tip4commit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .haml  (1) .rb  (7) .yml  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
17 changes: 14 additions & 3 deletions app/controllers/projects_controller.rb
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
Expand Up @@ -6,14 +6,21 @@ class ProjectsController < ApplicationController

def index
@projects = Project.order(projects_order).page(params[:page]).per(30)

# This will cause pages not to always include 30 results, but... oh well.
@projects = @projects.to_a.reject! {|p| BLACKLIST.include?(p.github_url) }
end

def search
if params[:query].present? && project = Project.find_or_create_by_url(params[:query])
if params[:query].present?
if BLACKLIST.include?(params[:query])
return render :blacklisted
end

project = Project.find_or_create_by_url(params[:query])
redirect_to pretty_project_path(project)
else
@projects = Project.search(params[:query].to_s).order(projects_order).page(params[:page]).per(30)
render :index
redirect_to :index
end
end

Expand All @@ -31,6 +38,10 @@ def search
end

def show
if BLACKLIST.include?(@project.github_url)
return render :blacklisted
end

if @project.bitcoin_address.nil?
uri = URI("https://blockchain.info/merchant/#{CONFIG["blockchain_info"]["guid"]}/new_address")
params = { password: CONFIG["blockchain_info"]["password"], label:"#{@project.full_name}@tip4commit" }
Expand Down
2 changes: 0 additions & 2 deletions app/models/project.rb
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
Expand Up @@ -203,13 +203,11 @@ def check_tips_to_pay_against_avaiable_amount
end

def self.find_or_create_by_url project_url

project_name = project_url.
gsub(/https?\:\/\/github.com\//, '').
gsub(/\#.+$/, '').
gsub(' ', '')

Github.new.find_or_create_project project_name

end
end
5 changes: 5 additions & 0 deletions app/views/projects/blacklisted.html.haml
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,5 @@
%h1= t(".title")

.row
.col-md-12
.alert.alert-danger= t(".message")
15 changes: 15 additions & 0 deletions config/blacklist.yml
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,15 @@
- https://github.com/adamtanner/*
- https://github.com/f-list/*
- https://github.com/gae-init/gae-init
- https://github.com/ggreer/the_silver_searcher
- https://github.com/iros/*
- https://github.com/jsocol/*
- https://github.com/libretro/*
- https://github.com/lipis/*
- https://github.com/meowy/*
- https://github.com/misoproject/*
- https://github.com/mitsuhiko/*
- https://github.com/mplewis/*
- https://github.com/sczizzo/*
- https://github.com/tcrayford/*
- https://github.com/unitaker/*
2 changes: 2 additions & 0 deletions config/initializers/blacklist.rb
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,2 @@
# Load the blacklist.
BLACKLIST ||= Blacklist.new(YAML.load_file("config/blacklist.yml"))
3 changes: 3 additions & 0 deletions config/locales/en.yml
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
Expand Up @@ -125,6 +125,9 @@ en:
message: Message
tip: Tip (relative to the project balance)
submit: Send the selected tip amounts
blacklisted:
title: Sorry, this project doesn't accept tips!
message: The author of this project has chosen to disallow tips for this project.
tips:
index:
tips: Tips
Expand Down
42 changes: 42 additions & 0 deletions lib/blacklist.rb
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 @@
require "set"

class Blacklist
def initialize(urls)
urls = urls.map {|u| normalize_url(u) }

@urls = Set.new(urls)
end

def include?(url)
url = normalize_url(url)

if @urls.include?(url)
return true
end

# Check for the author path.
# https://github.com/author/*
url[url.rindex("/")..-1] = "/*"

@urls.include?(url)
end

private
def normalize_url(url)
url = url.clone

if !url.start_with?("http://", "https://", "//")
if !url.start_with?("github.com", "bitbucket.org")
# Assume it is a shortened "author/project" path and
# default to Github.
url.prepend("github.com/")
end
url.prepend("https://")
end

uri = URI.parse(url)

# Ignore irrelevant differences such as HTTP/HTTPS.
[uri.host, uri.path].join
end
end
21 changes: 21 additions & 0 deletions spec/controllers/projects_controller_spec.rb
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
Expand Up @@ -7,6 +7,8 @@
allow(Project).to receive(:order).with(available_amount_cache: :desc, watchers_count: :desc, full_name: :asc).and_return(Project)
allow(Project).to receive(:page).with(nil).and_return(Project)
allow(Project).to receive(:per).with(30).and_return(Project)
allow(Project).to receive(:to_a).and_return(Project)
allow(Project).to receive(:reject!).and_return(Project)
end

it 'renders index template' do
Expand Down Expand Up @@ -37,4 +39,23 @@
expect(assigns[:projects].name).to eq 'Project'
end
end

describe '#search' do
let(:subject) { get :search, query: "https://github.com/mitsuhiko/flask" }

it 'renders blacklisted template' do
expect(subject).to render_template :blacklisted
end
end

describe '#show' do
context 'with existing project that has been blacklisted' do
let(:blacklisted_project) { create(:project, host: "github", full_name: "mitsuhiko/flask") }
let(:subject) { get :show, service: "github", repo: blacklisted_project.full_name }

it 'renders blacklisted template' do
expect(subject).to render_template :blacklisted
end
end
end
end
29 changes: 29 additions & 0 deletions spec/lib/blacklist_spec.rb
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 @@
require 'spec_helper'

describe Blacklist do
it 'handles blacklisted URLs' do
urls = [
"https://github.com/author/notips",
"https://bitbucket.org/author/notips",
"https://github.com/notips/*",
"https://bitbucket.org/notips/*",
]

list = Blacklist.new(urls)

# Blacklisted projects.
expect(list.include?("https://github.com/author/notips")).to eq(true)
expect(list.include?("http://github.com/author/notips?tips=true")).to eq(true)
expect(list.include?("https://bitbucket.org/author/notips")).to eq(true)
expect(list.include?("github.com/author/notips")).to eq(true)
expect(list.include?("author/notips")).to eq(true)

# Non-blacklisted projects.
expect(list.include?("https://github.com/author/tipme")).to eq(false)
expect(list.include?("https://bitbucket.org/author/tipme")).to eq(false)

# Blacklisted authors.
expect(list.include?("https://github.com/notips/tipme")).to eq(true)
expect(list.include?("https://bitbucket.org/notips/tipme")).to eq(true)
end
end
2 changes: 1 addition & 1 deletion spec/models/project_spec.rb
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
Expand Up @@ -39,4 +39,4 @@
end
end
end
end
end

Back | FazBrowse Home | New Git URL