| 
				
			 | 
			
			
				@@ -1,7 +1,8 @@ 
			 | 
		
	
		
			
			| 
				1
			 | 
			
				1
			 | 
			
			
				 class PeopleController < ApplicationController 
			 | 
		
	
		
			
			| 
				2
			 | 
			
				2
			 | 
			
			
				   before_action :set_person, only: [:show, :edit, :update, :destroy] 
			 | 
		
	
		
			
			| 
				3
			 | 
			
				
			 | 
			
			
				-  before_action :require_login! 
			 | 
		
	
		
			
			| 
				4
			 | 
			
				
			 | 
			
			
				-  before_action :require_admin!, except: [:show] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				3
			 | 
			
			
				+  before_action :set_person_from_token, only: [:calendar] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				4
			 | 
			
			
				+  before_action :require_login!, except: [:calendar] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				5
			 | 
			
			
				+  before_action :require_admin!, except: [:calendar, :show] 
			 | 
		
	
		
			
			| 
				5
			 | 
			
				6
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				6
			 | 
			
				7
			 | 
			
			
				   # GET /people 
			 | 
		
	
		
			
			| 
				7
			 | 
			
				8
			 | 
			
			
				   # GET /people.json 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -88,12 +89,59 @@ class PeopleController < ApplicationController 
			 | 
		
	
		
			
			| 
				88
			 | 
			
				89
			 | 
			
			
				     end 
			 | 
		
	
		
			
			| 
				89
			 | 
			
				90
			 | 
			
			
				   end 
			 | 
		
	
		
			
			| 
				90
			 | 
			
				91
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				92
			 | 
			
			
				+  # GET /c/:calendar_token 
			 | 
		
	
		
			
			| 
				
			 | 
			
				93
			 | 
			
			
				+  def calendar 
			 | 
		
	
		
			
			| 
				
			 | 
			
				94
			 | 
			
			
				+    cal = Icalendar::Calendar.new 
			 | 
		
	
		
			
			| 
				
			 | 
			
				95
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				96
			 | 
			
			
				+    @person.participants.joins(:activity).where('end > ?', 3.months.ago).each do |p| 
			 | 
		
	
		
			
			| 
				
			 | 
			
				97
			 | 
			
			
				+      a = p.activity 
			 | 
		
	
		
			
			| 
				
			 | 
			
				98
			 | 
			
			
				+      description_items = [a.description] 
			 | 
		
	
		
			
			| 
				
			 | 
			
				99
			 | 
			
			
				+      orgi = a.organizer_names 
			 | 
		
	
		
			
			| 
				
			 | 
			
				100
			 | 
			
			
				+      orgi_names = orgi.join ', ' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				101
			 | 
			
			
				+      orgi_line = case orgi.count 
			 | 
		
	
		
			
			| 
				
			 | 
			
				102
			 | 
			
			
				+                  when 0 then I18n.t 'activities.organizers.no_organizers' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				103
			 | 
			
			
				+                  when 1 then "#{I18n.t 'activities.organizers.one'}: #{orgi_names}" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				104
			 | 
			
			
				+                  else "#{I18n.t 'activities.organizers.other'}: #{orgi_names}" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				105
			 | 
			
			
				+                  end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				106
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				107
			 | 
			
			
				+      description_items << orgi_line 
			 | 
		
	
		
			
			| 
				
			 | 
			
				108
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				109
			 | 
			
			
				+      if a.subgroups.any? 
			 | 
		
	
		
			
			| 
				
			 | 
			
				110
			 | 
			
			
				+        if p.subgroup 
			 | 
		
	
		
			
			| 
				
			 | 
			
				111
			 | 
			
			
				+          description_items << "#{I18n.t 'activities.participant.yoursubgroup'}: #{p.subgroup}" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				112
			 | 
			
			
				+        end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				113
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				114
			 | 
			
			
				+        subgroup_names = a.subgroups.map(&:name).join ', ' 
			 | 
		
	
		
			
			| 
				
			 | 
			
				115
			 | 
			
			
				+        description_items << "#{I18n.t 'activerecord.models.subgroup.other'}: #{subgroup_names}" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				116
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				117
			 | 
			
			
				+      end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				118
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				119
			 | 
			
			
				+      cal.event do |e| 
			 | 
		
	
		
			
			| 
				
			 | 
			
				120
			 | 
			
			
				+        e.uid = group_activity_url a.group, a 
			 | 
		
	
		
			
			| 
				
			 | 
			
				121
			 | 
			
			
				+        e.dtstart = a.start 
			 | 
		
	
		
			
			| 
				
			 | 
			
				122
			 | 
			
			
				+        e.dtend = a.end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				123
			 | 
			
			
				+        e.summary = a.name 
			 | 
		
	
		
			
			| 
				
			 | 
			
				124
			 | 
			
			
				+        e.location = a.location 
			 | 
		
	
		
			
			| 
				
			 | 
			
				125
			 | 
			
			
				+        e.description = description_items.join "\n" 
			 | 
		
	
		
			
			| 
				
			 | 
			
				126
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				127
			 | 
			
			
				+        e.url = group_activity_url a.group, a 
			 | 
		
	
		
			
			| 
				
			 | 
			
				128
			 | 
			
			
				+      end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				129
			 | 
			
			
				+    end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				130
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				131
			 | 
			
			
				+    render plain: cal.to_ical 
			 | 
		
	
		
			
			| 
				
			 | 
			
				132
			 | 
			
			
				+  end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				133
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				91
			 | 
			
				134
			 | 
			
			
				   private 
			 | 
		
	
		
			
			| 
				92
			 | 
			
				135
			 | 
			
			
				     # Use callbacks to share common setup or constraints between actions. 
			 | 
		
	
		
			
			| 
				93
			 | 
			
				136
			 | 
			
			
				     def set_person 
			 | 
		
	
		
			
			| 
				94
			 | 
			
				137
			 | 
			
			
				       @person = Person.find(params[:id]) 
			 | 
		
	
		
			
			| 
				95
			 | 
			
				138
			 | 
			
			
				     end 
			 | 
		
	
		
			
			| 
				96
			 | 
			
				139
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				140
			 | 
			
			
				+    # Set person from calendar token 
			 | 
		
	
		
			
			| 
				
			 | 
			
				141
			 | 
			
			
				+    def set_person_from_token 
			 | 
		
	
		
			
			| 
				
			 | 
			
				142
			 | 
			
			
				+      @person = Person.find_by(calendar_token: params[:calendar_token]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				143
			 | 
			
			
				+    end 
			 | 
		
	
		
			
			| 
				
			 | 
			
				144
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				97
			 | 
			
				145
			 | 
			
			
				     # Never trust parameters from the scary internet, only allow the white list through. 
			 | 
		
	
		
			
			| 
				98
			 | 
			
				146
			 | 
			
			
				     def person_params 
			 | 
		
	
		
			
			| 
				99
			 | 
			
				147
			 | 
			
			
				       params.require(:person).permit(:first_name, :infix, :last_name, :email, :birth_date, :is_admin) 
			 |