diff --git a/.gitignore b/.gitignore index 5ced3ed..bd60f23 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ config/database.yml *.DS_Store *.swp .rvmrc - +vendor/bundle +.sass-cache/ diff --git a/Gemfile b/Gemfile index cb7a343..1986c09 100644 --- a/Gemfile +++ b/Gemfile @@ -1,28 +1,37 @@ source 'http://rubygems.org' source 'http://gemcutter.org' -gem 'rails', '3.0.5' -gem 'mongoid', '2.0.0.beta.20' +gem 'rails' +gem 'mongoid' gem 'bson_ext' gem 'yajl-ruby' gem 'will_paginate' gem 'rack-ssl' gem "bcrypt-ruby", :require => "bcrypt" -gem 'validate_url', '0.1.6' +gem 'validate_url' gem 'email_validator' gem 'chronic' gem 'jquery-rails' +gem 'haml-rails' + +# Gems used only for assets and not required +# in production environments by default. +group :assets do + gem 'sass-rails' + gem 'coffee-rails' + gem 'uglifier' +end + group :development, :test do - gem 'rspec-rails', '2.4.1' - gem 'cucumber-rails' + gem 'rspec-rails' gem 'steak' gem 'capybara' gem 'selenium-client' gem 'selenium-webdriver' gem 'launchy' gem 'shoulda' - gem 'factory_girl_rails', '1.1.beta1' + gem 'factory_girl_rails' gem 'webrat' gem 'autotest' gem 'autotest-growl' @@ -32,3 +41,11 @@ group :development, :test do gem 'delorean' gem 'rspec-set' end + +group :test do + gem 'cucumber-rails' +end + +group :development do + gem 'erb2haml' +end diff --git a/Gemfile.lock b/Gemfile.lock index 407a7f0..63b6383 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,177 +2,224 @@ GEM remote: http://rubygems.org/ remote: http://gemcutter.org/ specs: - ZenTest (4.5.0) - abstract (1.0.0) - actionmailer (3.0.5) - actionpack (= 3.0.5) - mail (~> 2.2.15) - actionpack (3.0.5) - activemodel (= 3.0.5) - activesupport (= 3.0.5) - builder (~> 2.1.2) - erubis (~> 2.6.6) - i18n (~> 0.4) - rack (~> 1.2.1) - rack-mount (~> 0.6.13) - rack-test (~> 0.5.7) - tzinfo (~> 0.3.23) - activemodel (3.0.5) - activesupport (= 3.0.5) - builder (~> 2.1.2) - i18n (~> 0.4) - activerecord (3.0.5) - activemodel (= 3.0.5) - activesupport (= 3.0.5) - arel (~> 2.0.2) - tzinfo (~> 0.3.23) - activeresource (3.0.5) - activemodel (= 3.0.5) - activesupport (= 3.0.5) - activesupport (3.0.5) - arel (2.0.9) + ZenTest (4.8.1) + actionmailer (3.2.6) + actionpack (= 3.2.6) + mail (~> 2.4.4) + actionpack (3.2.6) + activemodel (= 3.2.6) + activesupport (= 3.2.6) + builder (~> 3.0.0) + erubis (~> 2.7.0) + journey (~> 1.0.1) + rack (~> 1.4.0) + rack-cache (~> 1.2) + rack-test (~> 0.6.1) + sprockets (~> 2.1.3) + activemodel (3.2.6) + activesupport (= 3.2.6) + builder (~> 3.0.0) + activerecord (3.2.6) + activemodel (= 3.2.6) + activesupport (= 3.2.6) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activeresource (3.2.6) + activemodel (= 3.2.6) + activesupport (= 3.2.6) + activesupport (3.2.6) + i18n (~> 0.6) + multi_json (~> 1.0) + addressable (2.2.8) + arel (3.0.2) autotest (4.4.6) ZenTest (>= 4.4.1) - autotest-growl (0.2.9) - bcrypt-ruby (2.1.4) - bson (1.3.0) - bson_ext (1.3.0) - builder (2.1.2) - capybara (0.4.1.2) - celerity (>= 0.7.9) - culerity (>= 0.2.4) + autotest-growl (0.2.16) + bcrypt-ruby (3.0.1) + bcrypt-ruby (3.0.1-x86-mingw32) + bson (1.6.4) + bson_ext (1.6.4) + bson (~> 1.6.4) + builder (3.0.0) + capybara (1.1.2) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) - selenium-webdriver (>= 0.0.27) - xpath (~> 0.1.3) - celerity (0.8.9) - chalofa_ruby-progressbar (0.0.9.1) - childprocess (0.1.8) + selenium-webdriver (~> 2.0) + xpath (~> 0.1.4) + childprocess (0.3.2) ffi (~> 1.0.6) - chronic (0.3.0) - configuration (1.2.0) - cucumber (0.10.2) + chronic (0.6.7) + coffee-rails (3.2.2) + coffee-script (>= 2.2.0) + railties (~> 3.2.0) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.3.3) + cucumber (1.2.1) builder (>= 2.1.2) - diff-lcs (>= 1.1.2) - gherkin (>= 2.3.5) + diff-lcs (>= 1.1.3) + gherkin (~> 2.11.0) json (>= 1.4.6) - term-ansicolor (>= 1.0.5) - cucumber-rails (0.4.1) - cucumber (>= 0.10.1) - nokogiri (>= 1.4.4) - rack-test (>= 0.5.7) - culerity (0.2.15) - database_cleaner (0.6.6) - delorean (1.0.0) + cucumber-rails (1.3.0) + capybara (>= 1.1.2) + cucumber (>= 1.1.8) + nokogiri (>= 1.5.0) + database_cleaner (0.8.0) + delorean (1.2.0) chronic - diff-lcs (1.1.2) - email_validator (1.0.0) - erubis (2.6.6) - abstract (>= 1.0.0) - factory_girl (2.0.0.beta2) - factory_girl_rails (1.1.beta1) - factory_girl (~> 2.0.0.beta) - rails (>= 3.0.0) - ffi (1.0.7) - rake (>= 0.8.7) - fuubar (0.0.4) - chalofa_ruby-progressbar (~> 0.0.9) + diff-lcs (1.1.3) + email_validator (1.3.0) + activemodel + erb2haml (0.1.2) + haml + hpricot + ruby_parser + erubis (2.7.0) + execjs (1.4.0) + multi_json (~> 1.0) + factory_girl (3.5.0) + activesupport (>= 3.0.0) + factory_girl_rails (3.5.0) + factory_girl (~> 3.5.0) + railties (>= 3.0.0) + ffi (1.0.11) + fuubar (1.0.0) rspec (~> 2.0) - rspec-instafail (~> 0.1.4) - gherkin (2.3.5) + rspec-instafail (~> 0.2.0) + ruby-progressbar (~> 0.0.10) + gherkin (2.11.0) + json (>= 1.4.6) + gherkin (2.11.0-x86-mingw32) json (>= 1.4.6) - i18n (0.5.0) - jquery-rails (0.2.7) - rails (~> 3.0) - thor (~> 0.14.4) - json (1.5.1) - json_pure (1.5.1) - launchy (0.4.0) - configuration (>= 0.0.5) - rake (>= 0.8.1) - mail (2.2.15) - activesupport (>= 2.3.6) + haml (3.1.6) + haml-rails (0.3.4) + actionpack (~> 3.0) + activesupport (~> 3.0) + haml (~> 3.0) + railties (~> 3.0) + hike (1.2.1) + hpricot (0.8.6) + i18n (0.6.0) + journey (1.0.4) + jquery-rails (2.0.2) + railties (>= 3.2.0, < 5.0) + thor (~> 0.14) + json (1.7.3) + launchy (2.1.0) + addressable (~> 2.2.6) + libwebsocket (0.1.3) + addressable + mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) - mime-types (1.16) - mongo (1.3.0) - bson (>= 1.3.0) - mongoid (2.0.0.beta.20) - activemodel (~> 3.0) - mongo (~> 1.1) + mime-types (1.19) + mongo (1.6.2) + bson (~> 1.6.2) + mongoid (2.4.11) + activemodel (~> 3.1) + mongo (<= 1.6.2) tzinfo (~> 0.3.22) - will_paginate (~> 3.0.pre) - nokogiri (1.4.4) - polyglot (0.3.1) - rack (1.2.2) - rack-mount (0.6.14) - rack (>= 1.0.0) + multi_json (1.3.6) + nokogiri (1.5.4) + nokogiri (1.5.4-x86-mingw32) + polyglot (0.3.3) + rack (1.4.1) + rack-cache (1.2) + rack (>= 0.4) rack-ssl (1.3.2) rack - rack-test (0.5.7) + rack-test (0.6.1) rack (>= 1.0) - rails (3.0.5) - actionmailer (= 3.0.5) - actionpack (= 3.0.5) - activerecord (= 3.0.5) - activeresource (= 3.0.5) - activesupport (= 3.0.5) + rails (3.2.6) + actionmailer (= 3.2.6) + actionpack (= 3.2.6) + activerecord (= 3.2.6) + activeresource (= 3.2.6) + activesupport (= 3.2.6) bundler (~> 1.0) - railties (= 3.0.5) - railties (3.0.5) - actionpack (= 3.0.5) - activesupport (= 3.0.5) + railties (= 3.2.6) + railties (3.2.6) + actionpack (= 3.2.6) + activesupport (= 3.2.6) + rack-ssl (~> 1.3.2) rake (>= 0.8.7) - thor (~> 0.14.4) - rake (0.8.7) - rspec (2.4.0) - rspec-core (~> 2.4.0) - rspec-expectations (~> 2.4.0) - rspec-mocks (~> 2.4.0) - rspec-core (2.4.0) - rspec-expectations (2.4.0) - diff-lcs (~> 1.1.2) - rspec-instafail (0.1.7) - rspec-mocks (2.4.0) - rspec-rails (2.4.1) - actionpack (~> 3.0) - activesupport (~> 3.0) - railties (~> 3.0) - rspec (~> 2.4.0) + rdoc (~> 3.4) + thor (>= 0.14.6, < 2.0) + rake (0.9.2.2) + rdoc (3.12) + json (~> 1.4) + rspec (2.10.0) + rspec-core (~> 2.10.0) + rspec-expectations (~> 2.10.0) + rspec-mocks (~> 2.10.0) + rspec-core (2.10.1) + rspec-expectations (2.10.0) + diff-lcs (~> 1.1.3) + rspec-instafail (0.2.4) + rspec-mocks (2.10.1) + rspec-rails (2.10.1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec (~> 2.10.0) rspec-set (0.0.1) rspec (>= 2) - rubyzip (0.9.4) + ruby-progressbar (0.0.10) + ruby_parser (2.3.1) + sexp_processor (~> 3.0) + rubyzip (0.9.9) + sass (3.1.19) + sass-rails (3.2.5) + railties (~> 3.2.0) + sass (>= 3.1.10) + tilt (~> 1.3) selenium-client (1.2.18) - selenium-webdriver (0.1.4) - childprocess (>= 0.1.7) - ffi (>= 1.0.7) - json_pure + selenium-webdriver (2.24.0) + childprocess (>= 0.2.5) + libwebsocket (~> 0.1.3) + multi_json (~> 1.0) rubyzip - shoulda (2.11.3) - steak (1.1.0) - rspec (>= 1.3) - term-ansicolor (1.0.5) - thor (0.14.6) - treetop (1.4.9) + sexp_processor (3.2.0) + shoulda (3.0.1) + shoulda-context (~> 1.0.0) + shoulda-matchers (~> 1.0.0) + shoulda-context (1.0.0) + shoulda-matchers (1.0.0) + sprockets (2.1.3) + hike (~> 1.2) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + steak (2.0.0) + capybara (>= 1.0.0) + rspec-rails (>= 2.5.0) + thor (0.15.3) + tilt (1.3.3) + treetop (1.4.10) + polyglot polyglot (>= 0.3.1) - tzinfo (0.3.26) - validate_url (0.1.6) + tzinfo (0.3.33) + uglifier (1.2.5) + execjs (>= 0.3.0) + multi_json (~> 1.3) + validate_url (0.2.0) activemodel (>= 3.0.0) watchr (0.7) webrat (0.7.3) nokogiri (>= 1.2.0) rack (>= 1.0) rack-test (>= 0.5.3) - will_paginate (3.0.pre2) - xpath (0.1.3) + will_paginate (3.0.3) + xpath (0.1.4) nokogiri (~> 1.3) - yajl-ruby (0.8.2) + yajl-ruby (1.1.0) + yajl-ruby (1.1.0-x86-mingw32) PLATFORMS - ruby + x86-mingw32 DEPENDENCIES autotest @@ -181,24 +228,29 @@ DEPENDENCIES bson_ext capybara chronic + coffee-rails cucumber-rails database_cleaner delorean email_validator - factory_girl_rails (= 1.1.beta1) + erb2haml + factory_girl_rails fuubar + haml-rails jquery-rails launchy - mongoid (= 2.0.0.beta.20) + mongoid rack-ssl - rails (= 3.0.5) - rspec-rails (= 2.4.1) + rails + rspec-rails rspec-set + sass-rails selenium-client selenium-webdriver shoulda steak - validate_url (= 0.1.6) + uglifier + validate_url watchr webrat will_paginate diff --git a/public/images/help-us.png b/app/assets/images/help-us.png similarity index 100% rename from public/images/help-us.png rename to app/assets/images/help-us.png diff --git a/public/images/help-us.psd b/app/assets/images/help-us.psd similarity index 100% rename from public/images/help-us.psd rename to app/assets/images/help-us.psd diff --git a/public/images/screenshots/access.png b/app/assets/images/screenshots/access.png similarity index 100% rename from public/images/screenshots/access.png rename to app/assets/images/screenshots/access.png diff --git a/public/images/screenshots/admin-dashboard.png b/app/assets/images/screenshots/admin-dashboard.png similarity index 100% rename from public/images/screenshots/admin-dashboard.png rename to app/assets/images/screenshots/admin-dashboard.png diff --git a/public/images/screenshots/all-scope.png b/app/assets/images/screenshots/all-scope.png similarity index 100% rename from public/images/screenshots/all-scope.png rename to app/assets/images/screenshots/all-scope.png diff --git a/public/images/screenshots/authorization.png b/app/assets/images/screenshots/authorization.png similarity index 100% rename from public/images/screenshots/authorization.png rename to app/assets/images/screenshots/authorization.png diff --git a/public/images/screenshots/block-clients.png b/app/assets/images/screenshots/block-clients.png similarity index 100% rename from public/images/screenshots/block-clients.png rename to app/assets/images/screenshots/block-clients.png diff --git a/public/images/screenshots/client-show.png b/app/assets/images/screenshots/client-show.png similarity index 100% rename from public/images/screenshots/client-show.png rename to app/assets/images/screenshots/client-show.png diff --git a/public/images/screenshots/first-user-creation.png b/app/assets/images/screenshots/first-user-creation.png similarity index 100% rename from public/images/screenshots/first-user-creation.png rename to app/assets/images/screenshots/first-user-creation.png diff --git a/public/images/screenshots/pizzas-scope.png b/app/assets/images/screenshots/pizzas-scope.png similarity index 100% rename from public/images/screenshots/pizzas-scope.png rename to app/assets/images/screenshots/pizzas-scope.png diff --git a/public/images/screenshots/scopes.png b/app/assets/images/screenshots/scopes.png similarity index 100% rename from public/images/screenshots/scopes.png rename to app/assets/images/screenshots/scopes.png diff --git a/public/javascripts/application.js b/app/assets/javascripts/application.js similarity index 94% rename from public/javascripts/application.js rename to app/assets/javascripts/application.js index 2dadebd..d771dd7 100644 --- a/public/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1,5 +1,9 @@ // Place your application-specific JavaScript functions and classes here // This file is automatically included by javascript_include_tag :defaults +//= require jquery +//= require jquery_ujs +//= require_self +//= require_tree . $(document).ready(function () { $('input.tags').tagsInput({ diff --git a/public/javascripts/highcharts.js b/app/assets/javascripts/highcharts.js old mode 100755 new mode 100644 similarity index 100% rename from public/javascripts/highcharts.js rename to app/assets/javascripts/highcharts.js diff --git a/public/javascripts/jquery.tagsinput.js b/app/assets/javascripts/jquery.tagsinput.js similarity index 100% rename from public/javascripts/jquery.tagsinput.js rename to app/assets/javascripts/jquery.tagsinput.js diff --git a/public/stylesheets/.gitkeep b/app/assets/stylesheets/.gitkeep similarity index 100% rename from public/stylesheets/.gitkeep rename to app/assets/stylesheets/.gitkeep diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..8de70e3 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,4 @@ +/* +*= require_self +*= require_tree . +*/ \ No newline at end of file diff --git a/public/stylesheets/gh-buttons.css b/app/assets/stylesheets/gh-buttons.css similarity index 100% rename from public/stylesheets/gh-buttons.css rename to app/assets/stylesheets/gh-buttons.css diff --git a/public/stylesheets/gh-icons.png b/app/assets/stylesheets/gh-icons.png similarity index 100% rename from public/stylesheets/gh-icons.png rename to app/assets/stylesheets/gh-icons.png diff --git a/public/stylesheets/jquery.tagsinput.css b/app/assets/stylesheets/jquery.tagsinput.css similarity index 100% rename from public/stylesheets/jquery.tagsinput.css rename to app/assets/stylesheets/jquery.tagsinput.css diff --git a/public/stylesheets/reset.css b/app/assets/stylesheets/reset.css similarity index 100% rename from public/stylesheets/reset.css rename to app/assets/stylesheets/reset.css diff --git a/public/stylesheets/template.css b/app/assets/stylesheets/template.css similarity index 100% rename from public/stylesheets/template.css rename to app/assets/stylesheets/template.css diff --git a/app/controllers/accesses_controller.rb b/app/controllers/accesses_controller.rb index 8207c42..23811e4 100644 --- a/app/controllers/accesses_controller.rb +++ b/app/controllers/accesses_controller.rb @@ -27,7 +27,7 @@ def find_accesses end def find_access - @access = @accesses.id(params[:id]).first + @access = @accesses.for_ids(params[:id]).first unless @access redirect_to root_path, alert: "Resource not found." end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b44c844..464ee05 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,7 +19,7 @@ def json_body def authenticate if api_request - # oauth_authorized # uncomment to make all json API protected + oauth_authorized # uncomment to make all json API protected else session_auth end @@ -34,7 +34,7 @@ def json? end def session_auth - @current_user ||= User.criteria.id(session[:user_id]).first if session[:user_id] + @current_user ||= User.criteria.for_ids(session[:user_id]).first if session[:user_id] unless current_user session[:back] = request.url redirect_to(log_in_path) and return false @@ -61,12 +61,13 @@ def oauth_authorized def normalize_token # Token in the body - if (json_body and @body[:token]) + if request.env["HTTP_CONTENT_TYPE"] == "application/json" + json_body params[:token] = @body[:token] end # Token in the header - if request.env["Authorization"] - params[:token] = request.env["Authorization"].split(" ").last + if request.env["HTTP_AUTHORIZATION"] + params[:token] = request.env["HTTP_AUTHORIZATION"].split(" ").last end end diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 96ba356..34c1a67 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -71,7 +71,7 @@ def find_clients end def find_client - @client = @clients.id(params[:id]).first + @client = @clients.for_ids(params[:id]).first unless @client redirect_to root_path, alert: "Resource not found." end diff --git a/app/controllers/oauth/oauth_authorize_controller.rb b/app/controllers/oauth/oauth_authorize_controller.rb index 476b81e..d87a7fd 100644 --- a/app/controllers/oauth/oauth_authorize_controller.rb +++ b/app/controllers/oauth/oauth_authorize_controller.rb @@ -20,13 +20,13 @@ def create # section 4.1.1 - authorization code flow if params[:response_type] == "code" - @authorization = OauthAuthorization.create(client_uri: @client.uri, resource_owner_uri: current_user.uri, scope: params[:scope]) + @authorization = ::OauthAuthorization.create(client_uri: @client.uri, resource_owner_uri: current_user.uri, scope: params[:scope]) redirect_to authorization_redirect_uri(@client, @authorization, params[:state]) end # section 4.2.1 - implicit grant flow if params[:response_type] == "token" - @token = OauthToken.create(client_uri: @client.uri, resource_owner_uri: current_user.uri, scope: params[:scope]) + @token = ::OauthToken.create(client_uri: @client.uri, resource_owner_uri: current_user.uri, scope: params[:scope]) redirect_to implicit_redirect_uri(@client, @token, params[:state]) end end @@ -59,13 +59,13 @@ def client_blocked? end def access_blocked? - access = OauthAccess.find_or_create_by(:client_uri => @client.uri, resource_owner_uri: current_user.uri) + access = ::OauthAccess.find_or_create_by(:client_uri => @client.uri, resource_owner_uri: current_user.uri) access_blocked if access.blocked? end def token_blocked? if params[:response_type] == "token" - @token = OauthToken.exist(@client.uri, current_user.uri, params[:scope]).first + @token = ::OauthToken.exist(@client.uri, current_user.uri, params[:scope]).first token_blocked if @token and @token.blocked? end end @@ -73,7 +73,7 @@ def token_blocked? # @only refresh token for implicit flow def refresh_token if @token - @token = OauthToken.create(client_uri: @client.uri, resource_owner_uri: current_user.uri, scope: params[:scope]) + @token = ::OauthToken.create(client_uri: @client.uri, resource_owner_uri: current_user.uri, scope: params[:scope]) redirect_to implicit_redirect_uri(@client, @token, params[:state]) and return end end diff --git a/app/controllers/oauth/oauth_token_controller.rb b/app/controllers/oauth/oauth_token_controller.rb index 45d2bfe..92bd83d 100644 --- a/app/controllers/oauth/oauth_token_controller.rb +++ b/app/controllers/oauth/oauth_token_controller.rb @@ -27,21 +27,21 @@ class Oauth::OauthTokenController < ApplicationController def create # section 4.1.3 - authorization code flow if @body[:grant_type] == "authorization_code" - @token = OauthToken.create(client_uri: @client.uri, resource_owner_uri: @authorization.resource_owner_uri, scope: @authorization.scope) - @refresh_token = OauthRefreshToken.create(access_token: @token.token) + @token = ::OauthToken.create(client_uri: @client.uri, resource_owner_uri: @authorization.resource_owner_uri, scope: @authorization.scope) + @refresh_token = ::OauthRefreshToken.create(access_token: @token.token) render "/oauth/token" and return end # section 4.3.1 (password credentials flow) if @body[:grant_type] == "password" - @token = OauthToken.create(client_uri: @client.uri, resource_owner_uri: @resource_owner.uri, scope: @body[:scope]) - @refresh_token = OauthRefreshToken.create(access_token: @token.token) + @token = ::OauthToken.create(client_uri: @client.uri, resource_owner_uri: @resource_owner.uri, scope: @body[:scope]) + @refresh_token = ::OauthRefreshToken.create(access_token: @token.token) render "/oauth/token" and return end # section 6.0 (refresh token) if @body[:grant_type] == "refresh_token" - @token = OauthToken.create(client_uri: @expired_token.client_uri, resource_owner_uri: @expired_token.resource_owner_uri, scope: @expired_token.scope) + @token = ::OauthToken.create(client_uri: @expired_token.client_uri, resource_owner_uri: @expired_token.resource_owner_uri, scope: @expired_token.scope) render "/oauth/token" and return end end @@ -49,7 +49,7 @@ def create # simulate a logout blocking the token # TODO: refactoring def destroy - token = OauthToken.where(token: params[:id]).first + token = ::OauthToken.where(token: params[:id]).first if token token.block! return head 200 @@ -73,7 +73,7 @@ def client_where_secret_and_redirect def find_authorization if @body[:grant_type] == "authorization_code" - @authorization = OauthAuthorization.where_code_and_client_uri(@body[:code], @client.uri).first + @authorization = ::OauthAuthorization.where_code_and_client_uri(@body[:code], @client.uri).first @resource_owner_uri = @authorization.resource_owner_uri if @authorization message = "notifications.oauth.authorization.not_found" info = { code: @body[:code], client_id: @client.uri } @@ -131,7 +131,7 @@ def find_resource_owner def find_refresh_token if @body[:grant_type] == "refresh_token" @client = @client.first - @refresh_token = OauthRefreshToken.where(refresh_token: @body[:refresh_token]).first + @refresh_token = ::OauthRefreshToken.where(refresh_token: @body[:refresh_token]).first message = "notifications.oauth.refresh_token.not_found" info = { refresh_token: @body[:refresh_token] } render_422 message, info unless @refresh_token @@ -140,7 +140,7 @@ def find_refresh_token def find_expired_token if @body[:grant_type] == "refresh_token" - @expired_token = OauthToken.where(token: @refresh_token.access_token).first + @expired_token = ::OauthToken.where(token: @refresh_token.access_token).first @resource_owner_uri = @expired_token.resource_owner_uri message = "notifications.oauth.token.not_found" info = { token: @refresh_token.access_token } @@ -165,7 +165,7 @@ def client_blocked? end def access_blocked? - access = OauthAccess.find_or_create_by(:client_uri => @client.uri, resource_owner_uri: @resource_owner_uri) + access = ::OauthAccess.find_or_create_by(:client_uri => @client.uri, resource_owner_uri: @resource_owner_uri) message = "notifications.oauth.resource_owner.blocked_client" info = { client_id: @body[:client_id] } render_422 message, info if access.blocked diff --git a/app/controllers/scopes_controller.rb b/app/controllers/scopes_controller.rb index f77a151..e8e31c5 100644 --- a/app/controllers/scopes_controller.rb +++ b/app/controllers/scopes_controller.rb @@ -49,7 +49,7 @@ def destroy private def find_resource - @scope = Scope.criteria.id(params[:id]).first + @scope = Scope.criteria.for_ids(params[:id]).first unless @scope redirect_to root_path, alert: "Resource not found." end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 22e82d6..4aa5253 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -43,7 +43,7 @@ def update def find_user @user = current_user.admin? ? User.criteria : User.where(uri: current_user.uri) - @user = @user.id(params[:id]).first + @user = @user.for_ids(params[:id]).first unless @user redirect_to root_path, alert: "Resource not found." end diff --git a/app/models/client.rb b/app/models/client.rb index e18afa1..a56b08a 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -116,7 +116,7 @@ def block_authorizations! end def random_secret - self.secret = ActiveSupport::SecureRandom.hex(Oauth.settings["random_length"]) + self.secret = SecureRandom.hex(Oauth.settings["random_length"]) end def clean diff --git a/app/models/oauth/oauth_authorization.rb b/app/models/oauth/oauth_authorization.rb index 9374861..7244043 100644 --- a/app/models/oauth/oauth_authorization.rb +++ b/app/models/oauth/oauth_authorization.rb @@ -57,7 +57,7 @@ def where_code_and_client_uri(code, client_id) # random authorization code def random_code - self.code = ActiveSupport::SecureRandom.hex(Oauth.settings["random_length"]) + self.code = SecureRandom.hex(Oauth.settings["random_length"]) end # expiration time diff --git a/app/models/oauth/oauth_refresh_token.rb b/app/models/oauth/oauth_refresh_token.rb index 417e267..5d7a2e4 100644 --- a/app/models/oauth/oauth_refresh_token.rb +++ b/app/models/oauth/oauth_refresh_token.rb @@ -12,7 +12,7 @@ class OauthRefreshToken private def random_refresh_token - self.refresh_token = ActiveSupport::SecureRandom.hex(Oauth.settings["random_length"]) + self.refresh_token = SecureRandom.hex(Oauth.settings["random_length"]) end end diff --git a/app/models/oauth/oauth_token.rb b/app/models/oauth/oauth_token.rb index 8d0ba34..a1b76d0 100644 --- a/app/models/oauth/oauth_token.rb +++ b/app/models/oauth/oauth_token.rb @@ -62,11 +62,11 @@ def expired? private def random_token - self.token = ActiveSupport::SecureRandom.hex(Oauth.settings["random_length"]) + self.token = SecureRandom.hex(Oauth.settings["random_length"]) end def random_refresh_token - self.refresh_token = ActiveSupport::SecureRandom.hex(Oauth.settings["random_length"]) + self.refresh_token = SecureRandom.hex(Oauth.settings["random_length"]) end def create_expiration diff --git a/app/views/accesses/index.html.erb b/app/views/accesses/index.html.erb deleted file mode 100644 index 6f57146..0000000 --- a/app/views/accesses/index.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -

Show Accesses

- - - - - - - - -<% @accesses.each do |access| %> - - - - - <% if access.blocked? %> - - <% else %> - - <% end %> - - -<% end %> -
Client URI
<%= access.client_uri %><%= link_to 'Show stats', access_path(access), class: "button icon settings" %><%= link_to 'Unblock!', unblock_access_path(access), method: :put, class: "button danger" %><%= link_to 'Block!', block_access_path(access), method: :put, class: "button danger" %>
- -
diff --git a/app/views/accesses/index.html.haml b/app/views/accesses/index.html.haml new file mode 100644 index 0000000..382ef69 --- /dev/null +++ b/app/views/accesses/index.html.haml @@ -0,0 +1,15 @@ +%h2 Show Accesses +%table + %tr + %th Client URI + %th + %th + - @accesses.each do |access| + %tr + %td= access.client_uri + %td= link_to 'Show stats', access_path(access), class: "button icon settings" + - if access.blocked? + %td= link_to 'Unblock!', unblock_access_path(access), method: :put, class: "button danger" + - else + %td= link_to 'Block!', block_access_path(access), method: :put, class: "button danger" +%br/ diff --git a/app/views/accesses/show.html.erb b/app/views/accesses/show.html.erb deleted file mode 100644 index bfac325..0000000 --- a/app/views/accesses/show.html.erb +++ /dev/null @@ -1,35 +0,0 @@ -

Show Access

- -
- Client URI: - <%= @access.client_uri %> -
- -
- Today requests: - <%= @access.daily_requests.times %> -
- -
- -