summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-06-03 10:47:24 -0600
committermo khan <mo@mokhan.ca>2014-06-03 10:47:24 -0600
commit599ae644ff29aa0d1eda91ae604db62d83e7bddc (patch)
tree40208d04b2c49694d9f0728f77050b8558ec920a
parent4ca2bdc8f8125e6b888cf8dd517b02e204d0e884 (diff)
add migration to create users and resources tables and fix bug in services.
-rw-r--r--migrations.sql2
-rw-r--r--service.rb6
2 files changed, 5 insertions, 3 deletions
diff --git a/migrations.sql b/migrations.sql
new file mode 100644
index 0000000..488bcc4
--- /dev/null
+++ b/migrations.sql
@@ -0,0 +1,2 @@
+CREATE TABLE users(id integer primary key, name varchar(255), roles varchar(255));
+CREATE TABLE resources(id integer primary key, name varchar(255), roles varchar(255));
diff --git a/service.rb b/service.rb
index 60d0695..fcb1694 100644
--- a/service.rb
+++ b/service.rb
@@ -21,7 +21,7 @@ class RoleBased < ActiveRecord::Base
end
def roles
- str = read_attributes(:roles)
+ str = read_attribute(:roles)
str.split(/ *, */)
end
end
@@ -29,10 +29,9 @@ end
class User < RoleBased; end
class Resource < RoleBased; end
-
set :port, 3333
-post '/users/' do
+post '/users' do
auth = User.find_and_update_or_create(params)
auth ? 'Created' : 'Failed'
end
@@ -47,6 +46,7 @@ get '/users/:name/authorizations' do |name|
auth_roles = Resource.find_by_name(params[:resource]).roles rescue []
authorized = (user_roles - auth_roles).length != user_roles.length
+ puts "#{name} authorized to access #{params[:resource]} #{authorized}"
{
authorized: authorized