Commit e498eb61a9171266154152d6e80e515af27d560a

Authored by Niklas
1 parent 9b17ac08ab
Exists in master

fixes & added email column

Showing 4 changed files with 17 additions and 6 deletions Side-by-side Diff

... ... @@ -27,7 +27,7 @@
27 27 end
28 28  
29 29 get '/filters' do
30   - @filters = Filter.find(:all)
  30 + @filters = filters
31 31 haml :filters
32 32 end
33 33  
34 34  
35 35  
36 36  
37 37  
... ... @@ -35,28 +35,30 @@
35 35 if params[:id] == 'new'
36 36 @filter = Filter.new
37 37 else
38   - @filter = Filter.find(params[:id])
  38 + @filter = filters.find(params[:id])
39 39 end
40 40 haml :filter
41 41 end
42 42  
43 43 post '/filters' do
44 44 @filter = Filter.new(params[:filter])
  45 + @filter.email = session[:user]
45 46 @filter.save!
46 47 flash[:success] = "Filter created"
47 48 redirect("/filters")
48 49 end
49 50  
50 51 post '/filter/:id' do
51   - @filter = Filter.find(params[:id])
  52 + @filter = filters.find(params[:id])
52 53 @filter.update_attributes(params[:filter])
53 54 flash[:success] = "Filter updated"
  55 + @filter.email = session[:user]
54 56 @filter.save!
55 57 redirect("/filters")
56 58 end
57 59  
58 60 post '/filter/:id/delete' do
59   - @filter = Filter.find(params[:id])
  61 + @filter = filters.find(params[:id])
60 62 @filter.destroy
61 63 flash[:notice] = "Filter deleted"
62 64 redirect('/filters')
... ... @@ -97,6 +99,10 @@
97 99  
98 100 def option(value, label, selected)
99 101 "<option value=\"#{value}\"#{selected && ' selected'}>#{label}</option>"
  102 + end
  103 +
  104 + def filters
  105 + Filter.where(:email => session[:user])
100 106 end
101 107 end
102 108 end
maildrop_serializer.rb
... ... @@ -32,11 +32,11 @@
32 32 for exp in filter.expressions
33 33 post_flag = "h"
34 34 fe << " && " unless fe == ""
35   - if exp.field_name == "^Body"
  35 + if exp.field_name == "Body"
36 36 fe << "/"
37 37 post_flag = "b"
38 38 else
39   - fe << "/#{exp.field_name}:"
  39 + fe << "/^#{exp.field_name}:"
40 40 end
41 41 if exp.operator == 'contains'
42 42 fe << ".*(#{escape_expr_value(exp.expr_value)})/"
... ... @@ -37,6 +37,7 @@
37 37 has_many :expressions, :dependent => :destroy
38 38  
39 39 validates_presence_of :name
  40 + validates_presence_of :email
40 41 validates_presence_of :destination_folder
41 42  
42 43 def expressions=(hash_or_list)
43 44  
... ... @@ -74,8 +75,10 @@
74 75 c.class_eval do
75 76 def self.up
76 77 create_table :filters do |t|
  78 + t.string :email
77 79 t.string :name
78 80 t.string :destination_folder
  81 + t.string :filters
79 82 t.integer :order_num
80 83 t.timestamps
81 84 end
... ... @@ -15,5 +15,7 @@
15 15 %a.delete_filter_link{:href => "/filter/#{filter.id}/delete"} Delete
16 16 %div.span-14.last
17 17 %h2 Output
  18 + %p
  19 + %a{:href => "http://www.courier-mta.org/maildrop/maildropfilter.html"} (documentation)
18 20 %pre= MaildropSerializer.new.serialize(@filters)