Skip to content

Commit

Permalink
permissions - api for creating permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Strachota committed Jan 4, 2012
1 parent 5ceee56 commit 190b916
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/app/controllers/api/permissions_controller.rb
Expand Up @@ -12,9 +12,9 @@

class Api::PermissionsController < Api::ApiController

before_filter :find_role, :only => [:index]
before_filter :find_organization, :only => []
before_filter :find_permission, :only => [:destroy]
before_filter :find_role, :only => [:index, :create]
before_filter :find_organization, :only => [:create]
before_filter :find_permission, :only => [:destroy, :show]
before_filter :authorize
respond_to :json

Expand All @@ -36,11 +36,35 @@ def rules
end

def index
render :json => @role.permissions.to_json
render :json => @role.permissions.to_json()
end

def show
render :json => @permission.to_json(:include => [:tags, :verbs, :resource_type])
end

def create
render :json => "creating new permisson"

#{"name"=>"", "type"=>"", "verbs"=>[], "tags"=>[], "description"=>"", "organization_id"=>""}

new_params = {
:name => params[:name],
:description => params[:description],
:role => @role,
:organization => @organization
}
new_params[:verb_values] = params[:verbs] || []
new_params[:tag_values] = params[:tags] || []

if params[:type] == "all"
new_params[:all_tags] = true
new_params[:all_verbs] = true
end

new_params[:resource_type] = ResourceType.find_or_create_by_name(params[:type])

@permission = Permission.create! new_params
render :json => @permission.to_json(:include => [:tags, :verbs, :resource_type])
end

def destroy
Expand Down

0 comments on commit 190b916

Please sign in to comment.