Authorize creating requests for users, and add links for pennings to zeus requests

This commit is contained in:
benji 2017-01-11 14:34:17 +01:00
parent ad395945f2
commit a803d005a3
4 changed files with 7 additions and 2 deletions

View file

@ -19,6 +19,7 @@ class TransactionsController < ApplicationController
end end
else else
request = Request.new @transaction.info request = Request.new @transaction.info
authorize!(:create, request)
if request.save if request.save
render json: request, status: :created render json: request, status: :created
else else

View file

@ -47,7 +47,7 @@ class User < ActiveRecord::Base
end end
def self.zeus def self.zeus
find_or_create_by name: 'Zeus' @@zeus ||= find_or_create_by name: 'Zeus'
end end
end end

View file

@ -6,7 +6,7 @@ class UserAbility
can :manage, :all if user.penning? can :manage, :all if user.penning?
can :read, user, id: user.id can :read, user, id: user.id
can :manage, Request, user_id: user.id can :manage, Request, creditor_id: user.id
can :manage, Notification, user_id: user.id can :manage, Notification, user_id: user.id
can :create, Transaction do |t| can :create, Transaction do |t|
t.debtor == user && t.amount <= Rails.application.config.maximum_amount t.debtor == user && t.amount <= Rails.application.config.maximum_amount

View file

@ -7,6 +7,10 @@
- if current_user.penning - if current_user.penning
%li.pure-menu-item %li.pure-menu-item
=link_to "Zeus", User.zeus, class: "pure-menu-link" =link_to "Zeus", User.zeus, class: "pure-menu-link"
%li.pure-menu-item
= link_to "Requests (#{User.zeus.incoming_requests.size})", user_requests_path(User.zeus), class: 'pure-menu-link'
%li.pure-menu-item
= link_to "Notifications (#{User.zeus.notifications.size})", user_notifications_path(User.zeus), class: 'pure-menu-link'
%li.pure-menu-item %li.pure-menu-item
= link_to "Requests (#{current_user.incoming_requests.size})", user_requests_path(current_user), class: 'pure-menu-link' = link_to "Requests (#{current_user.incoming_requests.size})", user_requests_path(current_user), class: 'pure-menu-link'
%li.pure-menu-item %li.pure-menu-item