Commits

Anonymous committed 7ce25d1

add auth, label errors screen

  • Participants
  • Parent commits d678368

Comments (0)

Files changed (3)

File environment.rb

 require "json"
 
 Bundler.require
+require File.expand_path(File.dirname(__FILE__) + "/src/models.rb")
+require File.expand_path(File.dirname(__FILE__) + "/src/services.rb")
+require File.expand_path(File.dirname(__FILE__) + "/src/app.rb")
+require File.expand_path(File.dirname(__FILE__) + "/main.rb")
 
 case ENV['RACK_ENV']
 
   REDIS_PORT = '6379'
   REDIS_PASSWORD = nil
 
+  HTTP_AUTH_USERNAME = 'chloe'
+  HTTP_AUTH_PASSWORD = 'is a bell'
+
   # # clear and seed error data
   # MonkeyBadger::Data.clear!
   # MonkeyBadger::Data.import! File.expand_path(File.dirname(__FILE__) + "/data.json")
   REDIS_PORT = uri.port
   REDIS_PASSWORD = uri.password
 
+  HTTP_AUTH_USERNAME = ENV['HTTP_AUTH_USERNAME']
+  HTTP_AUTH_PASSWORD = ENV['HTTP_AUTH_PASSWORD']
+
   Pony.options = {
     via: :smtp,
     via_options: { 
     }
   }
 
-end
-
-require File.expand_path(File.dirname(__FILE__) + "/src/models.rb")
-require File.expand_path(File.dirname(__FILE__) + "/src/services.rb")
-require File.expand_path(File.dirname(__FILE__) + "/src/app.rb")
-require File.expand_path(File.dirname(__FILE__) + "/main.rb")
+end
     end
 
 
+
+    # use basic http authentication
+    use Rack::Auth::Basic, "Protected Area" do |username, password|
+      username == HTTP_AUTH_USERNAME && password == HTTP_AUTH_PASSWORD
+    end
+
+
+
     # we need to define routes based on services, so we create
     # them in a method that can be called after they have been attached
 
       get "/" do
         @count = Data.count
         @page = (params[:page] || 1).to_i
-        @page_size = 10
+        @page_size = 25
         @page_count = (@count / @page_size).ceil
         @errors = Data.errors @page, @page_size
         @actions = self.class.global_actions
         erb :error
       end
 
-      # display a form allowing a user to manually register errors
-      get "/new_error" do
-        erb :new_error
-      end
-
       # perform actions on errors
       actions.each do |action|
         post "/errors/:sha/actions/#{action.name}" do |sha|
           error = Data.get sha
           action.call sha, error
-          redirect "/errors/#{sha}"
+          redirect back
         end
       end
 
       global_actions.each do |action|
         post "/actions/#{action.name}" do
           action.call
-          redirect "/"
+          redirect back
         end
       end
+
+      # # display a form allowing a user to manually register errors
+      # get "/new_error" do
+      #   erb :new_error
+      # end
+
     end
   end
 end

File src/services.rb

         @max_counts = @categories.inject({}){|o, kv| o[kv[0]] = kv[1].values.max; o}
 
         erb :inspect_classifier
+      },
+      label_errors: -> (service) {
+        @count = Data.count
+        @page = (params[:page] || 1).to_i
+        @page_size = 25
+        @page_count = (@count / @page_size).ceil
+        @errors = Data.errors @page, @page_size
+        @actions = service.class::ACTIONS.map{|a| service.method a}
+
+        erb :label_errors
       }
     }