Bladeren bron

Add icalendar, token

Maarten van den Berg 6 jaren geleden
bovenliggende
commit
9ce1f07ab1

+ 3 - 0
Gemfile

@@ -67,6 +67,9 @@ gem 'daemons'
67 67
 # Error reporting
68 68
 gem 'sentry-raven'
69 69
 
70
+# Calendar support
71
+gem 'icalendar'
72
+
70 73
 group :development, :test do
71 74
   # Call 'byebug' anywhere in the code to stop execution and get a debugger console
72 75
   gem 'byebug', platform: :mri

+ 2 - 0
Gemfile.lock

@@ -89,6 +89,7 @@ GEM
89 89
     i18n (0.8.1)
90 90
     i18n_generators (2.1.1)
91 91
       rails (>= 3.0.0)
92
+    icalendar (2.4.1)
92 93
     jbuilder (2.6.3)
93 94
       activesupport (>= 3.0.0, < 5.2)
94 95
       multi_json (~> 1.2)
@@ -226,6 +227,7 @@ DEPENDENCIES
226 227
   font-awesome-sass
227 228
   haml
228 229
   i18n_generators
230
+  icalendar
229 231
   jbuilder (~> 2.5)
230 232
   jquery-rails
231 233
   listen (~> 3.0.5)

+ 6 - 0
app/models/person.rb

@@ -24,6 +24,11 @@ class Person < ApplicationRecord
24 24
   #   @return [String]
25 25
   #     the person's email address.
26 26
   #
27
+  # @!attribute calendar_token
28
+  #   @return [String]
29
+  #     the calendar token that can be used to open this Person's events as an
30
+  #     ICAL file.
31
+  #
27 32
   # @!attribute is_admin
28 33
   #   @return [Boolean]
29 34
   #     whether or not the person has administrative rights.
@@ -35,6 +40,7 @@ class Person < ApplicationRecord
35 40
     dependent: :destroy
36 41
   has_many :groups, through: :members
37 42
   has_many :activities, through: :participants
43
+  has_secure_token :calendar_token
38 44
 
39 45
   validates :email, uniqueness: true
40 46
   validates :first_name, presence: true

+ 6 - 0
db/migrate/20180904162042_add_calendar_token_to_people.rb

@@ -0,0 +1,6 @@
1
+class AddCalendarTokenToPeople < ActiveRecord::Migration[5.0]
2
+  def change
3
+    add_column :people, :calendar_token, :string
4
+    add_index :people, :calendar_token, unique: true
5
+  end
6
+end

+ 10 - 0
db/migrate/20180904163645_generate_calendar_tokens.rb

@@ -0,0 +1,10 @@
1
+class GenerateCalendarTokens < ActiveRecord::Migration[5.0]
2
+  def up
3
+    Person.all.each do |p|
4
+      p.regenerate_calendar_token
5
+    end
6
+  end
7
+
8
+  def down
9
+  end
10
+end

+ 3 - 1
db/schema.rb

@@ -10,7 +10,7 @@
10 10
 #
11 11
 # It's strongly recommended that you check this file into your version control system.
12 12
 
13
-ActiveRecord::Schema.define(version: 20180206181016) do
13
+ActiveRecord::Schema.define(version: 20180904163645) do
14 14
 
15 15
   create_table "activities", force: :cascade do |t|
16 16
     t.string   "name"
@@ -96,6 +96,8 @@ ActiveRecord::Schema.define(version: 20180206181016) do
96 96
     t.datetime "created_at",                              null: false
97 97
     t.datetime "updated_at",                              null: false
98 98
     t.boolean  "send_attendance_reminder", default: true
99
+    t.string   "calendar_token"
100
+    t.index ["calendar_token"], name: "index_people_on_calendar_token", unique: true
99 101
     t.index ["email"], name: "index_people_on_email", unique: true
100 102
   end
101 103