Skip to content

Commit

Permalink
Merge branch 'master' of Charcoal-SE/metasmoke
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug committed Aug 31, 2018
2 parents e79c03c + 394688d commit e3e6198
Show file tree
Hide file tree
Showing 43 changed files with 823 additions and 240 deletions.
82 changes: 75 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,69 @@
version: 2
jobs:
build:
js:
working_directory: ~/Charcoal-SE/metasmoke
parallelism: 1
shell: /bin/bash --login

docker:
- image: circleci/ruby:2.5-node

steps:
- checkout
- run: if [ -z "${NODE_ENV:-}" ]; then export NODE_ENV=test; fi
- run: export PATH="~/Charcoal-SE/metasmoke/node_modules/.bin:$PATH"
- restore_cache:
keys:
- v1-dep-js-{{ .Branch }}-
- v1-dep-js-master-
- v1-dep-js-
- run: npm install
- save_cache:
key: v1-dep-js-{{ .Branch }}-{{ epoch }}
paths:
- ./node_modules
- run: echo -e "export RAILS_ENV=test\nexport RACK_ENV=test" >> $BASH_ENV
- run: npm test

rubocop:
working_directory: ~/Charcoal-SE/metasmoke
parallelism: 1
shell: /bin/bash --login

environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results

docker:
- image: circleci/ruby:2.5-node
- image: circleci/mysql:5.7.22
environment:
MYSQL_ROOT_HOST: '%'
MYSQL_USER: 'ubuntu'
MYSQL_ROOT_PASSWORD: 'ubuntu'
MYSQL_DATABASE: 'metasmoke_test'

steps:
- run: sudo apt-get install apt-utils redis-server
- run: sudo service redis-server start
- checkout
- run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
- run: cp config/config.sample.yml config/config.yml
- restore_cache:
keys:
- v1-dep-rubocop-{{ .Branch }}-
- v1-dep-rubocop-master-
- v1-dep-rubocop-
- run: 'bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
--jobs=4 --retry=3 '
- save_cache:
key: v1-dep-rubocop-{{ .Branch }}-{{ epoch }}
paths:
- vendor/bundle
- ~/.bundle
- run: bundle exec rubocop -D

rails-tests:
working_directory: ~/Charcoal-SE/metasmoke
parallelism: 1
shell: /bin/bash --login
Expand Down Expand Up @@ -29,13 +92,9 @@ jobs:
- v1-dep-{{ .Branch }}-
- v1-dep-master-
- v1-dep-
- run: if [ -z "${NODE_ENV:-}" ]; then export NODE_ENV=test; fi
- run: export PATH="~/Charcoal-SE/metasmoke/node_modules/.bin:$PATH"
- run: npm install
- run: echo -e "export RAILS_ENV=test\nexport RACK_ENV=test" >> $BASH_ENV
- run: 'bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
--jobs=4 --retry=3 '
- run: curl -o- -L https://yarnpkg.com/install.sh | bash
- save_cache:
key: v1-dep-{{ .Branch }}-{{ epoch }}
paths:
Expand All @@ -57,14 +116,15 @@ jobs:
RACK_ENV: test
- run: bundle exec rake test:prepare
- run: bundle exec rake db:migrate
- run: npm test
- run: bundle exec rubocop -D
- run:
command: bundle exec rails test --verbose
environment:
RAILS_ENV: test
RACK_ENV: test
DISABLE_QUERY_LOGGER: true

- store_artifacts:
path: log
- store_test_results:
path: /tmp/circleci-test-results
- store_artifacts:
Expand All @@ -73,3 +133,11 @@ jobs:
path: coverage
- store_artifacts:
path: /tmp/circleci-test-results

workflows:
version: 2
build_and_test:
jobs:
- js
- rails-tests
- rubocop
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ gem 'groupdate', '~> 3.0.0'
gem 'rubocop', '~> 0.48.1', require: false, group: :test
gem 'simplecov', require: false, group: :test

gem 'blazer', '1.8.2'
gem 'blazer', '2.0.0', github: 'Charcoal-SE/blazer'
gem 'grape', '1.0.0'

# gem 'puma_worker_killer'
Expand Down
17 changes: 11 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ GIT
specs:
aescrypt (2.0.2)

GIT
remote: https://github.com/Charcoal-SE/blazer.git
revision: e88f71e0322bf2ff774b05a66999d24184684401
specs:
blazer (2.0.0)
activerecord (>= 4)
chartkick
railties (>= 4)
safely_block (>= 0.1.1)

GIT
remote: https://github.com/Charcoal-SE/capistrano-faster-assets.git
revision: e698f94623600eae9a51c6e924e9a7f4e5277c3e
Expand Down Expand Up @@ -115,11 +125,6 @@ GEM
backports (3.11.3)
bcrypt (3.1.12)
bindex (0.5.0)
blazer (1.8.2)
activerecord (>= 4)
chartkick
railties (>= 4)
safely_block (>= 0.1.1)
builder (3.2.3)
byebug (10.0.2)
callsite (0.0.11)
Expand Down Expand Up @@ -429,7 +434,7 @@ DEPENDENCIES
audited (~> 4.4)
awesome_print
aws-sdk-s3
blazer (= 1.8.2)
blazer (= 2.0.0)!
byebug
capistrano
capistrano-bundler
Expand Down
27 changes: 25 additions & 2 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,19 @@ body .profiler-results {
font-weight: bold;
}

.btn {
@mixin btn-sm {
padding: 0.45em 1em !important;
margin: 0 0.2em !important;
}

@mixin btn {
display: inline-block;
padding: 0.75em 1.25em !important;
border-radius: 3px !important;
text-decoration: none;
box-shadow: inset 0 1px white;
transition: all 0.2s ease;
margin: 0 0.3em !important;

&:hover {
transition: all 0.2s ease;
Expand Down Expand Up @@ -297,6 +303,23 @@ body .profiler-results {
}

&.btn-sm {
padding: 0.45em 1em !important;
@include btn-sm;
}
}

.btn {
@include btn;
}

div.btn-sm {
padding: 0 !important;
margin: 0 0.4em;

.bs-placeholder {
@include btn-sm;
}

& + .btn-sm {
padding: calc(0.45em + 2px) 1em !important;
}
}
19 changes: 19 additions & 0 deletions app/assets/stylesheets/domain_links.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Place all the styles related to the DomainLinks controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

.domain-link {
padding: 0.5em 0;
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;

& + .domain-link {
border-top: 0;
}

blockquote {
border-left: 4px solid #ddd;
padding-left: 1em;
font-size: 1em;
}
}
43 changes: 43 additions & 0 deletions app/controllers/domain_links_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

class DomainLinksController < ApplicationController
before_action :verify_core
before_action :set_link, except: :create

def create
@link = DomainLink.new link_params.merge(creator: current_user)
if @link.save
Rails.cache.delete :domain_link_types
render partial: 'domain_links/link', locals: { link: @link, domain: @link.left }
else
render json: { success: false }, status: 500
end
end

def update
if @link.update link_params
render partial: 'domain_links/link', locals: { link: @link, domain: @link.left }
else
render json: { success: false }, status: 500
end
end

def destroy
if @link.destroy
redirect_back fallback_location: root_path
else
flash[:danger] = 'Failed to remove link.'
redirect_back fallback_location: @link.left
end
end

private

def link_params
params.require(:domain_link).permit(:left_id, :right_id, :comments, :link_type)
end

def set_link
@link = DomainLink.find params[:id]
end
end
8 changes: 3 additions & 5 deletions app/controllers/domain_tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ def index
end

def add
@tag = DomainTag.find_or_create_by name: params[:tag_name]
@domain = SpamDomain.find params[:domain_id]
if @domain.domain_tags.include? @tag
flash[:danger] = "This domain already has the tag '#{@tag.name}'."
else
@domain.domain_tags << @tag
@domain.domain_tags = params[:tag_name].map do |tag_name|
DomainTag.find_or_create_by name: tag_name
end
@domain.save
redirect_to spam_domain_path(@domain)
end

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/github_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def pull_request_hook
domains = text.scan(/<!-- METASMOKE-BLACKLIST-WEBSITE (.*?) -->/)

domains.each do |domain|
domain = SearchHelper.regex_support domain[0]
domain = domain[0]

num_tps = Post.where('body REGEXP ?', domain).where(is_tp: true).count
num_fps = Post.where('body REGEXP ?', domain).where(is_fp: true).count
Expand All @@ -81,7 +81,7 @@ def pull_request_hook
keywords = text.scan(/<!-- METASMOKE-BLACKLIST-KEYWORD (.*?) -->/)

keywords.each do |keyword|
keyword = SearchHelper.regex_support keyword[0]
keyword = keyword[0]

num_tps = Post.where('body REGEXP ?', keyword).where(is_tp: true).count
num_fps = Post.where('body REGEXP ?', keyword).where(is_fp: true).count
Expand All @@ -93,7 +93,7 @@ def pull_request_hook
usernames = text.scan(/<!-- METASMOKE-BLACKLIST-USERNAME (.*?) -->/)

usernames.each do |username|
username = SearchHelper.regex_support username[0]
username = username[0]

num_tps = Post.where('username REGEXP ?', username).where(is_tp: true).count
num_fps = Post.where('username REGEXP ?', username).where(is_fp: true).count
Expand All @@ -105,7 +105,7 @@ def pull_request_hook
watches = text.scan(/<!-- METASMOKE-BLACKLIST-WATCH_KEYWORD (.*?) -->/)

watches.each do |watch|
watch = SearchHelper.regex_support watch[0]
watch = watch[0]

num_tps = Post.where('body REGEXP ?', watch).where(is_tp: true).count
num_fps = Post.where('body REGEXP ?', watch).where(is_fp: true).count
Expand Down
11 changes: 5 additions & 6 deletions app/controllers/spam_domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ def index
else
SpamDomain.all
end.includes(:domain_tags).order(domain: :asc).paginate(page: params[:page], per_page: 100)
@counts = {
all: @domains.joins(:posts).group(Arel.sql('spam_domains.id')).count,
tp: @domains.joins(:posts).where(posts: { is_tp: true }).group(Arel.sql('spam_domains.id')).count,
fp: @domains.joins(:posts).where(posts: { is_fp: true }).group(Arel.sql('spam_domains.id')).count,
naa: @domains.joins(:posts).where(posts: { is_naa: true }).group(Arel.sql('spam_domains.id')).count
}
SpamDomain.preload_post_counts(@domains)
end

def create
Expand Down Expand Up @@ -62,6 +57,10 @@ def destroy
end
end

def query
render json: SpamDomain.where('domain LIKE ?', "%#{params[:q]}%").map { |d| { value: d.id, text: d.domain } }
end

private

def set_spam_domain
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/domain_links_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

module DomainLinksHelper
end
2 changes: 1 addition & 1 deletion app/helpers/reasons_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.check_for_inactive_reasons
def self.calculate_weights_for_flagging
Reason.all.each do |reason|
if reason.posts.count > 20
reason.update(weight: [reason.tp_percentage * 100, reason.maximum_weight].compact.min)
reason.update(weight: [(reason.tp_percentage * 100).round, reason.maximum_weight].compact.min)
else
reason.update(weight: 0)
end
Expand Down
17 changes: 0 additions & 17 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def self.parse_search_params(params, symbol, user)
else
false
end
input = regex_support input
else
operation = 'LIKE'
input = '%' + ActiveRecord::Base.sanitize_sql_like(input) + '%'
Expand All @@ -26,20 +25,4 @@ def self.is_regex?(symbol) # rubocop:disable Style/PredicateName
def self.is_inverse_regex?(symbol) # rubocop:disable Style/PredicateName
(symbol.to_s + '_is_inverse_regex').to_sym
end

def self.regex_support(text)
{
'\w' => '[a-zA-Z0-9_]',
'\W' => '[^a-zA-Z0-9_]',
'\s' => '[\r\n\t\f\v ]',
'\S' => '[^\r\n\t\f\v ]',
'\d' => '[0-9]',
'\D' => '[^0-9]',
'\b' => '(^|[[:<:]]|[[:>:]]|$)',
'(?:' => '('
}.each do |k, v|
text = text.gsub k, v
end
text
end
end

0 comments on commit e3e6198

Please sign in to comment.