Commit d6efeeb39232fd53515a647b8db81cca23e24134
1 parent
a6a2573d
Exists in
master
and in
1 other branch
finish off notification modeling
Showing
2 changed files
with
18 additions
and
1 deletions
Show diff stats
app/controllers/apps_controller.rb
... | ... | @@ -29,12 +29,14 @@ class AppsController < InheritedResources::Base |
29 | 29 | def create |
30 | 30 | @app = App.new(params[:app]) |
31 | 31 | initialize_subclassed_issue_tracker |
32 | + initialize_subclassed_notification_service | |
32 | 33 | create! |
33 | 34 | end |
34 | 35 | |
35 | 36 | def update |
36 | 37 | @app = resource |
37 | 38 | initialize_subclassed_issue_tracker |
39 | + initialize_subclassed_notification_service | |
38 | 40 | update! |
39 | 41 | end |
40 | 42 | |
... | ... | @@ -70,6 +72,7 @@ class AppsController < InheritedResources::Base |
70 | 72 | end |
71 | 73 | |
72 | 74 | def initialize_subclassed_issue_tracker |
75 | + # set the app's issue tracker | |
73 | 76 | if params[:app][:issue_tracker_attributes] && tracker_type = params[:app][:issue_tracker_attributes][:type] |
74 | 77 | if IssueTracker.subclasses.map(&:name).concat(["IssueTracker"]).include?(tracker_type) |
75 | 78 | @app.issue_tracker = tracker_type.constantize.new(params[:app][:issue_tracker_attributes]) |
... | ... | @@ -77,6 +80,15 @@ class AppsController < InheritedResources::Base |
77 | 80 | end |
78 | 81 | end |
79 | 82 | |
83 | + def initialize_subclassed_notification_service | |
84 | + # set the app's notification service | |
85 | + if params[:app][:notification_service_attributes] && notification_type = params[:app][:notification_service_attributes][:type] | |
86 | + if NotificationService.subclasses.map(&:name).concat(["NotificationService"]).include?(notification_type) | |
87 | + @app.notification_service = notification_type.constantize.new(params[:app][:notification_service_attributes]) | |
88 | + end | |
89 | + end | |
90 | + end | |
91 | + | |
80 | 92 | def begin_of_association_chain |
81 | 93 | # Filter the @apps collection to apps watched by the current user, unless user is an admin. |
82 | 94 | # If user is an admin, then no filter is applied, and all apps are shown. |
... | ... | @@ -90,7 +102,7 @@ class AppsController < InheritedResources::Base |
90 | 102 | def plug_params app |
91 | 103 | app.watchers.build if app.watchers.none? |
92 | 104 | app.issue_tracker = IssueTracker.new unless app.issue_tracker_configured? |
93 | - app.notification_service = NotificationService.new | |
105 | + app.notification_service = NotificationService.new unless app.notification_service_configured? | |
94 | 106 | app.copy_attributes_from(params[:copy_attributes_from]) if params[:copy_attributes_from] |
95 | 107 | end |
96 | 108 | ... | ... |
app/models/app.rb
... | ... | @@ -124,6 +124,11 @@ class App |
124 | 124 | !!(issue_tracker && issue_tracker.class < IssueTracker && issue_tracker.project_id.present?) |
125 | 125 | end |
126 | 126 | |
127 | + def notification_service_configured? | |
128 | + !!(notification_service && notification_service.class < NotificationService && notification_service.api_token.present?) | |
129 | + end | |
130 | + | |
131 | + | |
127 | 132 | def notification_recipients |
128 | 133 | if notify_all_users |
129 | 134 | (User.all.map(&:email).reject(&:blank?) + watchers.map(&:address)).uniq | ... | ... |