meetalendar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rubocop.yml +96 -0
- data/.travis.yml +21 -0
- data/Gemfile +20 -0
- data/LICENSE +20 -0
- data/README.md +141 -0
- data/Rakefile +5 -0
- data/app/controllers/comfy/admin/meetalendar/meetups_controller.rb +154 -0
- data/app/models/comfy/admin/meetalendar/auth_credential.rb +22 -0
- data/app/models/comfy/admin/meetalendar/meetup_group.rb +3 -0
- data/app/models/comfy/admin/meetalendar/meetups_calendar_syncer.rb +178 -0
- data/app/models/comfy/admin/meetalendar/meetups_controller_logic.rb +77 -0
- data/app/models/google/auth/store/db_token_store.rb +37 -0
- data/app/views/comfy/admin/meetalendar/meetups/_authorize_calendar.slim +6 -0
- data/app/views/comfy/admin/meetalendar/meetups/_edit.slim +6 -0
- data/app/views/comfy/admin/meetalendar/meetups/_search_mask.slim +19 -0
- data/app/views/comfy/admin/meetalendar/meetups/_search_result.slim +57 -0
- data/app/views/comfy/admin/meetalendar/meetups/authorize_calendar.slim +6 -0
- data/app/views/comfy/admin/meetalendar/meetups/edit.slim +11 -0
- data/app/views/comfy/admin/meetalendar/meetups/index.slim +26 -0
- data/app/views/comfy/admin/meetalendar/meetups/search_mask.slim +5 -0
- data/app/views/comfy/admin/meetalendar/meetups/search_result.slim +5 -0
- data/app/views/comfy/admin/meetalendar/partials/_navigation.html.haml +9 -0
- data/app/views/layouts/comfy/meetalendar/application.html.erb +28 -0
- data/bin/bundle +3 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/bin/setup +36 -0
- data/bin/update +31 -0
- data/bin/yarn +11 -0
- data/comfy_meetalendar.gemspec +44 -0
- data/config.ru +6 -0
- data/config/application.rb +38 -0
- data/config/boot.rb +7 -0
- data/config/database.yml +11 -0
- data/config/environment.rb +7 -0
- data/config/environments/development.rb +64 -0
- data/config/environments/test.rb +51 -0
- data/config/initializers/meetalendar.rb +23 -0
- data/config/locales/en.yml +33 -0
- data/config/meetalendar_routes.rb +3 -0
- data/config/storage.yml +35 -0
- data/db/migrate/00_create_cms.rb +142 -0
- data/db/migrate/01_create_meetalendar_meetup_groups.rb +13 -0
- data/db/migrate/02_create_meetalendar_auth_credentials.rb +16 -0
- data/lib/generators/comfy/meetalendar/README +5 -0
- data/lib/generators/comfy/meetalendar/meetalendar_generator.rb +61 -0
- data/lib/meetalendar.rb +29 -0
- data/lib/meetalendar/configuration.rb +24 -0
- data/lib/meetalendar/engine.rb +32 -0
- data/lib/meetalendar/routes/meetalendar_admin.rb +30 -0
- data/lib/meetalendar/routing.rb +3 -0
- data/lib/meetalendar/version.rb +7 -0
- data/lib/tasks/meetalendar_tasks.rake +14 -0
- metadata +244 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 73604a9cc0b86b606d42ffe229c51672b3ea933edb58c1392c65b15a11f1aead
|
4
|
+
data.tar.gz: a0e8b7fcd6e9c163e054933198a0b3aafe224738ce541081b96fc1db11f28b6c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a50451ed147c3bb6b9b45721bb8ca0a01af9be07f47139f027aed7789358b489f6de88c3cbabc8ee6cbfbb8081e10289c97d1649e52e3b3907a1dfbb4bd73508
|
7
|
+
data.tar.gz: 286e5134a8173857b29d7425795ab11eb1eb2e373ecfcdaff1dc18c6108a31cde45ef672bfb5e79fee0d83d104714e907c4b90d82df6d7841517555495222638
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
Exclude:
|
4
|
+
- bin/*
|
5
|
+
- db/schema.rb
|
6
|
+
- db/migrate/**/*
|
7
|
+
- test/fixtures/**/*
|
8
|
+
- tmp/**/*
|
9
|
+
|
10
|
+
# -- Performance ---------------------------------------------------------------
|
11
|
+
Performance/Casecmp:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
# -- Metrics -------------------------------------------------------------------
|
15
|
+
Metrics/PerceivedComplexity:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Metrics/ParameterLists:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Metrics/LineLength:
|
28
|
+
Max: 120
|
29
|
+
|
30
|
+
Metrics/CyclomaticComplexity:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Metrics/ClassLength:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Metrics/BlockLength:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Metrics/AbcSize:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
# -- Layout --------------------------------------------------------------------
|
43
|
+
Layout/MultilineOperationIndentation:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Layout/MultilineMethodCallIndentation:
|
47
|
+
EnforcedStyle: indented
|
48
|
+
|
49
|
+
Layout/MultilineHashBraceLayout:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Layout/IndentArray:
|
53
|
+
EnforcedStyle: consistent
|
54
|
+
|
55
|
+
Layout/EmptyLinesAroundModuleBody:
|
56
|
+
EnforcedStyle: empty_lines_except_namespace
|
57
|
+
|
58
|
+
Layout/EmptyLinesAroundExceptionHandlingKeywords:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Layout/EmptyLinesAroundClassBody:
|
62
|
+
EnforcedStyle: empty_lines_except_namespace
|
63
|
+
|
64
|
+
Layout/AlignParameters:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Layout/AccessModifierIndentation:
|
68
|
+
EnforcedStyle: outdent
|
69
|
+
|
70
|
+
# -- Style ---------------------------------------------------------------------
|
71
|
+
Style/StringLiterals:
|
72
|
+
EnforcedStyle: double_quotes
|
73
|
+
|
74
|
+
Style/RegexpLiteral:
|
75
|
+
EnforcedStyle: percent_r
|
76
|
+
|
77
|
+
Style/Lambda:
|
78
|
+
EnforcedStyle: literal
|
79
|
+
|
80
|
+
Style/IfUnlessModifier:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
Style/GuardClause:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Style/Documentation:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
Style/DateTime:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
Style/ClassAndModuleChildren:
|
93
|
+
Enabled: false
|
94
|
+
|
95
|
+
Style/AsciiComments:
|
96
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.3.7
|
4
|
+
- 2.4.4
|
5
|
+
- 2.5.1
|
6
|
+
- ruby-head
|
7
|
+
gemfile:
|
8
|
+
- test/gemfiles/5.2.gemfile
|
9
|
+
branches:
|
10
|
+
only:
|
11
|
+
- master
|
12
|
+
before_install:
|
13
|
+
- gem update --system
|
14
|
+
- gem update bundler
|
15
|
+
script:
|
16
|
+
- bundle exec rake db:migrate
|
17
|
+
- bundle exec rake test
|
18
|
+
- bundle exec rubocop
|
19
|
+
matrix:
|
20
|
+
allow_failures:
|
21
|
+
- rvm: ruby-head
|
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
gem 'comfortable_mexican_sofa', '~> 2.0', '>= 2.0.18'
|
8
|
+
|
9
|
+
group :development, :test do
|
10
|
+
gem "kaminari", "~> 1.1.1"
|
11
|
+
gem "sqlite3", "~> 1.3.13"
|
12
|
+
end
|
13
|
+
|
14
|
+
# group :development do
|
15
|
+
# end
|
16
|
+
|
17
|
+
# group :test do
|
18
|
+
# end
|
19
|
+
|
20
|
+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013-2018 Oleg Khabarov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# Meetalendar
|
2
|
+
TLDR: It allows the user to subscribe to meetup-groups events.
|
3
|
+
|
4
|
+
This gem prensents all the needed functionality to search for relevant groups on meetup, remember the chosen ones and offers a task that can be called regularely to transcribe the meetup-groups events to a google calendar.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
With the gem installed as described, it will have added itself to the admin interface. Navigte to it and find the two buttons that help you authorize the client with the meetup api and the google calendar api.
|
8
|
+
After authorization you can search for Meetup groups via the 'Add Groups' button. There you will be presented with a search mask formular with some default values for the 'find groups' Meetup Api call. (Check the [Meetup Api documentation](https://secure.meetup.com/meetup_api/console/?path=/find/groups) for more options.)
|
9
|
+
|
10
|
+
Then click search and you will be presented with the found groups for your search mask. (Or with groups in the area if you entered to little information and Meetup took your accounts location info to find groups near you.)
|
11
|
+
Then select the groups you want to "subscribe" to, enter the cities names that are "approved" and save them. With approved is meant, that only events of a selected group that are happening in an approved city are copied over into the google calendar. Thus avoiding "spamming", your google calendar with events that don't happen in the approved cities near you. (Most groups happen to meet in the same place each time while other groups events can happen to be spread out quite far.)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'meetalendar'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
```bash
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
```bash
|
27
|
+
$ gem install meetalendar
|
28
|
+
```
|
29
|
+
|
30
|
+
Then run this generator that copies over setup, migrations and views:
|
31
|
+
```bash
|
32
|
+
$ rails generate comfy:meetalendar
|
33
|
+
```
|
34
|
+
|
35
|
+
And lastly run the migrations with:
|
36
|
+
```bash
|
37
|
+
$ rake db:migrate
|
38
|
+
```
|
39
|
+
Or sometimes:
|
40
|
+
```bash
|
41
|
+
$ bundle exec rake db:migrate
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
Just try your best.
|
46
|
+
|
47
|
+
## License
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
49
|
+
|
50
|
+
|
51
|
+
## More detailed (system environment) setup guide for admins
|
52
|
+
|
53
|
+
### Meetup API OAuth2 Credentials
|
54
|
+
How to get the Meetup OAuth2 Authentification set up:
|
55
|
+
|
56
|
+
- Go to the meetup web console to tab OAuth Consumers: [Meetup OAUth Consumers](https://secure.meetup.com/meetup_api/oauth_consumers/)
|
57
|
+
- Click on »Create one now«
|
58
|
+
|
59
|
+
I filled this page in like this:
|
60
|
+
```text
|
61
|
+
Consumer name: Meetalendar,
|
62
|
+
Application Website: https://www.hicknhack-software.com/it-events,
|
63
|
+
Who are you requesting access for?: I am requesting access for my organization,
|
64
|
+
What is the organization name?: HicknHack Software GmbH,
|
65
|
+
Phone number: 0123456789,
|
66
|
+
Description: We use the Meetup API to gather IT-Events in our city and surroundings to display them as part of our Local IT-Event Calendar. Up to now this was done by hand and shall now be replaced by some logic. (The calendar is public and free of cost or commercial interests.),
|
67
|
+
Platform Terms of Service: Yes, I agree.,
|
68
|
+
```
|
69
|
+
-> The phone number is random, please check [our website](https://www.hicknhack-software.com/) if you want to do buisness with us.
|
70
|
+
|
71
|
+
With this altered to fit your company and everything setup correctly you might have to wait one or two days until Meetup grants you premission. (When i tried this it seemed to be done by hand.)
|
72
|
+
|
73
|
+
When the time has come and your credentials are granted you will have to put them in the credentials.json, that will also have the google calendar credentials, like shown below.
|
74
|
+
|
75
|
+
### Google OAuth2 Credentials
|
76
|
+
Hot to get the Google Calendar OAuth2 Authentification set up:
|
77
|
+
|
78
|
+
- Follow this good source: [Google Ruby OAuth2 official Tutorial](https://developers.google.com/calendar/quickstart/ruby) Wich has a nice Button that seems to have a lot of functionaity. If confused it might help make things easier to setup. (Especially getting the credentials.json)
|
79
|
+
- Good general expanation: [Source of belows steps](https://support.google.com/cloud/answer/6158849?hl=en) -> That i "quopied" it's most relevant section:
|
80
|
+
|
81
|
+
```text
|
82
|
+
_Setting up OAuth 2.0_
|
83
|
+
|
84
|
+
To create an OAuth 2.0 client ID in the console:
|
85
|
+
- Go to the [Google Cloud Platform Console](https://console.cloud.google.com/?pli=1).
|
86
|
+
- From the projects list, select a project or create a new one.
|
87
|
+
- If the APIs & services page isn't already open, open the console left side menu and select APIs & services.
|
88
|
+
- On the left, click Credentials.
|
89
|
+
- Click New Credentials, then select OAuth client ID.
|
90
|
+
- Note: If you're unsure whether OAuth 2.0 is appropriate for your project, select Help me choose and follow the instructions to pick the right credentials.
|
91
|
+
|
92
|
+
- Select the appropriate application type for your project and enter any additional information required. Application types are described in more detail in the following sections.
|
93
|
+
- If this is your first time creating a client ID, you can also configure your consent screen by clicking Consent Screen. (The following procedure explains how to set up the Consent screen.) You won't be prompted to configure the consent screen after you do it the first time.
|
94
|
+
- Click Create client ID
|
95
|
+
- To delete a client ID, go to the Credentials page, check the box next to the ID, and then click Delete.
|
96
|
+
```
|
97
|
+
|
98
|
+
### Putting both credentials in one credential.json file
|
99
|
+
|
100
|
+
Meetalendar will need get the credentials we aquired. It will know where to look when we have set the needed environment variable ```MEETALENDAR_CREDENTIALS_FILEPATH``` to point to the credentials.json file that we will create like so:
|
101
|
+
|
102
|
+
Correct annonymified example:
|
103
|
+
```json
|
104
|
+
{
|
105
|
+
"google_calendar": {
|
106
|
+
"installed": {
|
107
|
+
"client_id": "123456789-abcdefghijklmnopqrstuvwxyz123456789.apps.googleusercontent.com",
|
108
|
+
"project_id": "testprojectidgoogl-123456789",
|
109
|
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
110
|
+
"token_uri": "https://oauth2.googleapis.com/token",
|
111
|
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
112
|
+
"client_secret": "abcdefghijklmnopqrstuvwxyz123456789",
|
113
|
+
"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"]
|
114
|
+
}
|
115
|
+
},
|
116
|
+
"meetup": {
|
117
|
+
"client_id": "abcdefghijklmnopqrstuvwxyz123456789",
|
118
|
+
"client_secret": "abcdefghijklmnopqrstuvwxyz123456789"
|
119
|
+
}
|
120
|
+
}
|
121
|
+
```
|
122
|
+
|
123
|
+
Wich was created from the credentials.json coming from google that looked like so:
|
124
|
+
```json
|
125
|
+
{
|
126
|
+
"installed": {
|
127
|
+
"client_id": "123456789-abcdefghijklmnopqrstuvwxyz123456789.apps.googleusercontent.com",
|
128
|
+
"project_id": "testprojectidgoogl-123456789",
|
129
|
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
130
|
+
"token_uri": "https://oauth2.googleapis.com/token",
|
131
|
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
132
|
+
"client_secret": "abcdefghijklmnopqrstuvwxyz123456789",
|
133
|
+
"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"]
|
134
|
+
}
|
135
|
+
}
|
136
|
+
```
|
137
|
+
|
138
|
+
Basically the google calendar credentials where wrapped and put a nesting lower to allow the choice between loading meetup or google credentials. This allows to only have one environment variable needed to be set up and is also expandable for other credentials shall the need arise.
|
139
|
+
|
140
|
+
If you need help setting up the needed ```MEETALENDAR_CREDENTIALS_FILEPATH``` environment variable then find help from this [friendly duck](https://duckduckgo.com/?q=set+environment+variable+for+windows%2Flinux%2Fmac&ia=web).
|
141
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_resource'
|
3
|
+
|
4
|
+
class Comfy::Admin::Meetalendar::MeetupsController < Comfy::Admin::Cms::BaseController
|
5
|
+
before_action :build_meetup_group, only: [:new, :create]
|
6
|
+
before_action :load_meetup_group, only: [:show, :edit, :update, :destroy]
|
7
|
+
|
8
|
+
def index
|
9
|
+
@meetups = Comfy::Admin::Meetalendar::MeetupGroup.page(params[:page])
|
10
|
+
end
|
11
|
+
|
12
|
+
def search_mask
|
13
|
+
render
|
14
|
+
end
|
15
|
+
|
16
|
+
def search_result
|
17
|
+
search_result = Comfy::Admin::Meetalendar::MeetupsControllerLogic.search_result(params_permit_parameters[:parameters], Time.now)
|
18
|
+
@groups_id_name = search_result.groups_id_name
|
19
|
+
@found_upcoming_grouped_events = search_result.found_upcoming_grouped_events
|
20
|
+
@found_last_grouped_events = search_result.found_last_grouped_events
|
21
|
+
@meetup_groups = search_result.meetup_groups
|
22
|
+
rescue ::ActiveResource::UnauthorizedAccess => exception
|
23
|
+
flash[:error] = "Could not load groups and events from meetup. Is the client authorized to the Meetup API?"
|
24
|
+
redirect_to(action: :index) and return
|
25
|
+
end
|
26
|
+
|
27
|
+
def authorize_calendar
|
28
|
+
@goto_url = Comfy::Admin::Meetalendar::MeetupsCalendarSyncer.get_authorization_url
|
29
|
+
key_code = params_permit_key_code[:key_code]
|
30
|
+
if !key_code.nil?
|
31
|
+
begin
|
32
|
+
Comfy::Admin::Meetalendar::MeetupsCalendarSyncer.authorize_and_remember(key_code)
|
33
|
+
flash[:success] = "Calendar successfully authorized."
|
34
|
+
rescue ::ActiveResource::UnauthorizedAccess => exception
|
35
|
+
flash[:error] = exception.message.to_s
|
36
|
+
ensure
|
37
|
+
(redirect_to(action: :index) and return)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def authorize_meetup
|
43
|
+
redirect_to(Comfy::Admin::Meetalendar::MeetupsControllerLogic::authorize_meetup(request, callback_comfy_admin_meetalendar_meetups_path(@site).to_s)) and return
|
44
|
+
end
|
45
|
+
|
46
|
+
def callback
|
47
|
+
begin
|
48
|
+
Comfy::Admin::Meetalendar::MeetupsControllerLogic::callback(params_permit_code[:code], request, callback_comfy_admin_meetalendar_meetups_path(@site).to_s)
|
49
|
+
flash[:success] = "Meetup successfully authorized."
|
50
|
+
rescue ::ActiveResource::ClientError => ex
|
51
|
+
flash[:error] = ex.message.to_s
|
52
|
+
ensure
|
53
|
+
redirect_to(action: :index) and return
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def failure
|
58
|
+
# TODO(Schau): Possibly there are arguments given to this function/route containing more info on why meetup api authorization failed.
|
59
|
+
flash[:error] = "Meetup authorization failed."
|
60
|
+
redirect_to(action: :index) and return
|
61
|
+
end
|
62
|
+
|
63
|
+
def create
|
64
|
+
@selected_groups_ids = params_permit_selected[:selected_groups_ids]
|
65
|
+
if @selected_groups_ids.nil?
|
66
|
+
flash[:error] = "Could not create new Meetup subscription(s) as no Meetup groups where selected."
|
67
|
+
else
|
68
|
+
@selected_groups_ids.each do |selected_id|
|
69
|
+
already_present_meetup = Comfy::Admin::Meetalendar::MeetupGroup.where(group_id: selected_id).first
|
70
|
+
|
71
|
+
group_data = params_permit_id(selected_id)
|
72
|
+
|
73
|
+
if group_data.nil?
|
74
|
+
flash[:error] = flash[:error].to_s + " + No group data was present for group id: #{selected_id}"
|
75
|
+
else
|
76
|
+
if already_present_meetup.nil?
|
77
|
+
@meetup = Comfy::Admin::Meetalendar::MeetupGroup.new({"group_id": selected_id, "name": group_data[:name], "approved_cities": group_data[:approved_cities], "group_link": group_data[:group_link]})
|
78
|
+
@meetup.save!
|
79
|
+
else
|
80
|
+
already_present_meetup.name = group_data[:name]
|
81
|
+
already_present_meetup.approved_cities = group_data[:approved_cities]
|
82
|
+
already_present_meetup.group_link = group_data[:group_link]
|
83
|
+
already_present_meetup.save!
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
# TODO(Schau): Check if this works as intended! flash[:error].blank? instead?
|
88
|
+
flash[:success] = "Created or Updated new Meetup Subscription(s)." if flash[:error].nil?
|
89
|
+
end
|
90
|
+
redirect_to(action: :index) and return
|
91
|
+
end
|
92
|
+
|
93
|
+
def edit
|
94
|
+
render
|
95
|
+
end
|
96
|
+
|
97
|
+
def update
|
98
|
+
edited_approved_cities = params_permit_edited_approved_cities[:edited_approved_cities]
|
99
|
+
if edited_approved_cities.nil?
|
100
|
+
flash[:error] = "New approved cities could not be read. Please try again."
|
101
|
+
redirect_to(action: :edit) and return
|
102
|
+
else
|
103
|
+
@meetup.approved_cities = edited_approved_cities
|
104
|
+
@meetup.save!
|
105
|
+
flash[:success] = "Edited Meetup Subscription."
|
106
|
+
redirect_to(action: :index) and return
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def destroy
|
111
|
+
@meetup.destroy
|
112
|
+
flash[:success] = 'Meetup deleted'
|
113
|
+
redirect_to(action: :index) and return
|
114
|
+
end
|
115
|
+
|
116
|
+
protected
|
117
|
+
|
118
|
+
def build_meetup_group
|
119
|
+
@meetup = Comfy::Admin::Meetalendar::MeetupGroup.new(meetup_params)
|
120
|
+
end
|
121
|
+
|
122
|
+
def load_meetup_group
|
123
|
+
@meetup = Comfy::Admin::Meetalendar::MeetupGroup.find(params[:id])
|
124
|
+
rescue ActiveRecord::RecordNotFound
|
125
|
+
flash.now[:danger] = 'Meetup Group not found'
|
126
|
+
redirect_to action: :index
|
127
|
+
end
|
128
|
+
|
129
|
+
def meetup_params
|
130
|
+
params.fetch(:meetup, {}).permit(:name, :group_id, :approved_cities, :group_link)
|
131
|
+
end
|
132
|
+
def params_permit_parameters
|
133
|
+
params.permit(:parameters)
|
134
|
+
end
|
135
|
+
def params_permit_selected
|
136
|
+
params.permit({selected_groups_ids: []})
|
137
|
+
end
|
138
|
+
def params_permit_id(selected)
|
139
|
+
res = params.require(:groups).permit("#{selected}": [:name, :approved_cities, :group_link])
|
140
|
+
res[selected]
|
141
|
+
end
|
142
|
+
def params_permit_switch
|
143
|
+
params.permit(:switch)
|
144
|
+
end
|
145
|
+
def params_permit_key_code
|
146
|
+
params.permit(:key_code)
|
147
|
+
end
|
148
|
+
def params_permit_code
|
149
|
+
params.permit(:code)
|
150
|
+
end
|
151
|
+
def params_permit_edited_approved_cities
|
152
|
+
params.permit(:edited_approved_cities)
|
153
|
+
end
|
154
|
+
end
|