forked from bofh/fetsite
AutoCommit Mon Jun 8 22:03:14 CEST 2015
This commit is contained in:
1
app/controllers/.#calentries_controller.rb
Symbolic link
1
app/controllers/.#calentries_controller.rb
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
andreas@andreas-ThinkPad-S430.13138:1433770009
|
||||||
@@ -48,7 +48,7 @@ u=current_user
|
|||||||
end
|
end
|
||||||
|
|
||||||
def current_ability
|
def current_ability
|
||||||
@current_ability ||= Ability.new(current_user, request)
|
@current_ability ||= Ability.new(current_user, request, params[:key])
|
||||||
end
|
end
|
||||||
def default_url_options
|
def default_url_options
|
||||||
{locale: I18n.locale, theme: nil , ansicht: nil}
|
{locale: I18n.locale, theme: nil , ansicht: nil}
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ class CalendarsController < ApplicationController
|
|||||||
# GET /calendars.json
|
# GET /calendars.json
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
def index
|
def index
|
||||||
@calendars = Calendar.all
|
@calendars = Calendar.accessible_by(current_ability)
|
||||||
@calentries = Calentry.all
|
@calentries = Calentry.accessible_by(current_ability)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.json { render json: @calendars }
|
format.json { render json: @calendars }
|
||||||
|
format.ics
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class CalentriesController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {redirect_to rubriken_path}
|
format.html {redirect_to rubriken_path}
|
||||||
|
format.ics
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
class Ability
|
class Ability
|
||||||
include CanCan::Ability
|
include CanCan::Ability
|
||||||
def initialize(user,request=nil)
|
def initialize(user,request=nil,key=nil)
|
||||||
loggedin=!(user.nil?)
|
loggedin=!(user.nil?)
|
||||||
|
unless key.nil?
|
||||||
|
k=Key.find_by_uuid(key)
|
||||||
|
if !k.nil? && k.is_valid && k.typ == 0
|
||||||
|
user=k.user
|
||||||
|
end
|
||||||
|
end
|
||||||
user ||= User.new # guest user (not logged in)
|
user ||= User.new # guest user (not logged in)
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +109,7 @@ end
|
|||||||
can :index, Rubrik
|
can :index, Rubrik
|
||||||
can [:show], Rubrik, :public=>true
|
can [:show], Rubrik, :public=>true
|
||||||
can [:list], Neuigkeit, :cache_is_published=>true, :rubrik=>{:public=>true}
|
can [:list], Neuigkeit, :cache_is_published=>true, :rubrik=>{:public=>true}
|
||||||
can :show, Neuigkeit, :rubrik=>{:public=>true}
|
can :show, Neuigkeit, :cache_is_published=>true, :rubrik=>{:public=>true}
|
||||||
|
|
||||||
if loggedin
|
if loggedin
|
||||||
end
|
end
|
||||||
@@ -163,7 +169,7 @@ end
|
|||||||
can [:showics], Calendar
|
can [:showics], Calendar
|
||||||
can [:show], Calentry
|
can [:show], Calentry
|
||||||
|
|
||||||
if( user.has_role?("fetuser") || user.has_role?("fetadmin"))
|
if( user.has_role?("fetuser") || user.has_role?("fetadmin")|| (!k.nil? && k.typ==1 && (k.user.has_role?("fetuser")||k.user.has_role?("fetadmin"))))
|
||||||
can [:show,:index], Calendar
|
can [:show,:index], Calendar
|
||||||
can [:edit, :update,:new,:create,:verwalten], Calendar
|
can [:edit, :update,:new,:create,:verwalten], Calendar
|
||||||
can [:edit, :update,:new,:create,:verwalten,:delete], Calentry
|
can [:edit, :update,:new,:create,:verwalten,:delete], Calentry
|
||||||
|
|||||||
11
app/models/key.rb
Normal file
11
app/models/key.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class Key < ActiveRecord::Base
|
||||||
|
attr_accessible :expire, :is_valid, :type, :user_id
|
||||||
|
belongs_to :parent, :polymorphic => true
|
||||||
|
belongs_to :user
|
||||||
|
before_create :create_unique_identifier
|
||||||
|
def create_unique_identifier
|
||||||
|
begin
|
||||||
|
self.uuid = SecureRandom.hex(10) # or whatever you chose like UUID tools
|
||||||
|
end while self.class.exists?(:uuid => uuid)
|
||||||
|
end
|
||||||
|
end
|
||||||
24
app/views/calendars/index.ics.erb
Normal file
24
app/views/calendars/index.ics.erb
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
BEGIN:VCALENDAR
|
||||||
|
VERSION:2.0
|
||||||
|
PRODID:http://www.example.com/calendarapplication/
|
||||||
|
METHOD:PUBLISH
|
||||||
|
X-WR-TIMEZONE:Europe/Vienna
|
||||||
|
BEGIN:VTIMEZONE
|
||||||
|
TZID:Europe/Vienna
|
||||||
|
BEGIN:DAYLIGHT
|
||||||
|
TZOFFSETFROM:+0100
|
||||||
|
DTSTART:19810329T020000
|
||||||
|
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
|
||||||
|
TZNAME:MESZ
|
||||||
|
END:DAYLIGHT
|
||||||
|
BEGIN:STANDARD
|
||||||
|
TZOFFSETFROM:+0200
|
||||||
|
DTSTART:19961027T030000
|
||||||
|
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
|
||||||
|
TZNAME:MEZ
|
||||||
|
END:STANDARD
|
||||||
|
END:VTIMEZONE
|
||||||
|
<% @calentries.each do |entry| %>
|
||||||
|
<%= render entry %>
|
||||||
|
<% end %>
|
||||||
|
END:VCALENDAR
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
<%= render 'calendars/calentries', :object=>@calentries %>
|
<%= render 'calendars/calentries', :object=>@calentries %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= link_to "ics-format", calendar_path(@rubrik.calendar,:format=>:ics) %>
|
<%= link_to "ics-format", calendar_path(@rubrik.calendar,:format=>:ics,:key=>current_user.nil? ? nil : Key.where(typ: 1, user_id: current_user.id,is_valid: true).last.try(:uuid)) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
15
db/migrate/20150608193256_create_keys.rb
Normal file
15
db/migrate/20150608193256_create_keys.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class CreateKeys < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :keys do |t|
|
||||||
|
t.string :uuid
|
||||||
|
t.datetime :expire
|
||||||
|
t.string :parent_type
|
||||||
|
t.integer:parent_id
|
||||||
|
t.integer :typ
|
||||||
|
t.integer :user_id
|
||||||
|
t.boolean :is_valid
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
11
spec/factories/keys.rb
Normal file
11
spec/factories/keys.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
FactoryGirl.define do
|
||||||
|
factory :key do
|
||||||
|
uuid "MyString"
|
||||||
|
expire "2015-06-08 21:32:56"
|
||||||
|
parent ""
|
||||||
|
type 1
|
||||||
|
user_id 1
|
||||||
|
is_valid false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
5
spec/models/key_spec.rb
Normal file
5
spec/models/key_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Key, :type => :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user