Skip to content

Commit 66cc704

Browse files
committed
Adding support for importing old DB
1 parent 957da72 commit 66cc704

File tree

16 files changed

+190
-30
lines changed

16 files changed

+190
-30
lines changed

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
config/settings.local.yml
1919
config/settings/*.local.yml
2020
config/environments/*.local.yml
21-
.yardoc
21+
.yardoc
22+
db/tables

‎app/assets/stylesheets/elements.less‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
.refiddle-corpus
6565
{
6666
margin: @padding-base-horizontal 0;
67+
max-height: 300px;
68+
overflow: hidden;
69+
white-space: pre-wrap;
6770
}
6871
}
6972

‎app/models/ability.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def authenticated
2424

2525
can [:update,:read], user
2626
can [:update,:share], Refiddle, user: user
27+
can [:update], Refiddle, locked: false, share: true
2728

2829
user.roles && user.roles.each{|r| send r if respond_to? r}
2930

@@ -32,7 +33,7 @@ def authenticated
3233

3334
def anonymous
3435
can [:read,:new,:create,:fork], Refiddle, share: true
35-
can [:update], Refiddle, locked: false
36+
# can [:update], Refiddle, locked: false, share: true
3637
end
3738

3839
def staff

‎app/models/refiddle.rb‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Refiddle
1010
validate :no_urls_when_shared
1111
validate :not_unchanged_sample
1212
validate :not_unchanged_fork
13+
validate :not_spam
1314

1415
honey_pot :email
1516

@@ -190,15 +191,16 @@ def create_sample(attrs={})
190191
URL_PATTERN = /\w+\.[a-z]{2,}/i
191192
PROTOCOL_PATTERN = /[a-z]+:\/\/?\w+/i
192193
LINK_PATTERN = /href|src|rel=/i
194+
STACKOVERFLOW_PATTERN = /https?:\/\/stackoverflow.com/i
193195
SAMPLE_ATTRS = { regex: "/k[^\\s]*s/g", corpus_text: "I can haz kittens. Mmmm. Tasty, tasty kittens.", replace_text: "tacos" }.freeze
194196

195197
def validate_no_url(field)
196198
val = send(field)
197-
errors.add field, "may not include url or link like text when shared" if PROTOCOL_PATTERN =~ val || URL_PATTERN =~ val || LINK_PATTERN =~ val
199+
errors.add field, "may not include url or link like text unless you are signed in" if ( PROTOCOL_PATTERN =~ val || LINK_PATTERN =~ val ) && STACKOVERFLOW_PATTERN !~ val
198200
end
199201

200202
def no_urls_when_shared
201-
if share
203+
if share && ! user
202204
%w{ title description corpus_text replace_text }.each do |field|
203205
validate_no_url(field)
204206
end
@@ -229,5 +231,15 @@ def create_short_code
229231
code
230232
end
231233

234+
def not_spam
235+
if ( title && title == description ) || regex == corpus_text || "/#{regex}/" == corpus_text || corpus_text == replace_text ||
236+
( description && corpus_text.include?(description) )
237+
errors.add :base, "Something doesn't look quite right"
238+
end
239+
if tags.present? && tags.any?{|t| /^[+-]?\d+$/ =~ t || /[A-Z]{2,}[a-z]+[A-Z]{2,}/ =~ t }
240+
errors.add :base, "Something doesn't look quite right"
241+
end
242+
end
243+
232244

233245
end

‎app/models/refiddle_pattern.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class RefiddlePattern
1111
# @!attribute
1212
# @return [String] the actual regex pattern
1313
field :regex, type: String
14-
validates :regex, format: LITERALEXP_PATTERN
1514

1615
# @!attribute
1716
# @return [String] corupus of text to test the {#regex} against.
1817
field :corpus_text, type: String
18+
validates_presence_of :corpus_text
1919

2020
# @!attribute
2121
# @return [String] the pattern to use when replacing matches from {#corpus_text} against {#regex}.

‎app/views/refiddles/_form.html.haml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
= render "pre_asside"
5555
= render "refiddles/asside", refiddle: refiddle, f: f
5656

57+
- if can?(:delete,refiddle) && ! refiddle.new_record?
58+
%p= button_to "Delete", refiddle_path(refiddle), method: :delete, class: "btn btn-danger"
5759

5860
- content_for :page_actions do
5961
.btn-group.navbar-left

‎app/views/refiddles/_refiddle.html.haml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
.label.label-default=tag
1616
.refiddle-regex= refiddle.regex
1717
.refiddle-description!= refiddle.description
18-
.refiddle-corpus!= refiddle.corpus_text.gsub( /\n/, "<br />" )
18+
.refiddle-corpus= refiddle.corpus_text
1919
.refiddle-actions
2020
= link_to "Open", refiddle_path(refiddle), class: "btn btn-default"
2121
= link_to "Fork", refiddle_path(refiddle,fork: true), class: "btn btn-default"

‎app/views/refiddles/show.html.haml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
= render "refiddles/form", refiddle: @refiddle, fork: @fork, original: @original
1+
= render "refiddles/form", refiddle: @refiddle, fork: @fork, original: @original

‎app/views/sessions/_signin_form.html.haml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- return_to ||= dashboard_path
1+
- return_to ||= root_path
22
- return_to = URI.escape( return_to )
33
.row
44
.col-sm-5

‎app/views/tagged/index.html.haml‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
- content_for :asside do
1010
%h4 Tags
11-
%ul.tag-cloud
12-
- @tags.each do |tag|
13-
%li><= link_to tag, tagged_path(tag)
11+
%p
12+
%ul.tag-cloud
13+
- @tags.each do |tag|
14+
%li><= link_to tag, tagged_path(tag)
15+
16+
%p
17+
%small.text-muted= page_entries_info @refiddles

0 commit comments

Comments
 (0)