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,12 +29,14 @@ class AppsController < InheritedResources::Base | ||
29 | def create | 29 | def create |
30 | @app = App.new(params[:app]) | 30 | @app = App.new(params[:app]) |
31 | initialize_subclassed_issue_tracker | 31 | initialize_subclassed_issue_tracker |
32 | + initialize_subclassed_notification_service | ||
32 | create! | 33 | create! |
33 | end | 34 | end |
34 | 35 | ||
35 | def update | 36 | def update |
36 | @app = resource | 37 | @app = resource |
37 | initialize_subclassed_issue_tracker | 38 | initialize_subclassed_issue_tracker |
39 | + initialize_subclassed_notification_service | ||
38 | update! | 40 | update! |
39 | end | 41 | end |
40 | 42 | ||
@@ -70,6 +72,7 @@ class AppsController < InheritedResources::Base | @@ -70,6 +72,7 @@ class AppsController < InheritedResources::Base | ||
70 | end | 72 | end |
71 | 73 | ||
72 | def initialize_subclassed_issue_tracker | 74 | def initialize_subclassed_issue_tracker |
75 | + # set the app's issue tracker | ||
73 | if params[:app][:issue_tracker_attributes] && tracker_type = params[:app][:issue_tracker_attributes][:type] | 76 | if params[:app][:issue_tracker_attributes] && tracker_type = params[:app][:issue_tracker_attributes][:type] |
74 | if IssueTracker.subclasses.map(&:name).concat(["IssueTracker"]).include?(tracker_type) | 77 | if IssueTracker.subclasses.map(&:name).concat(["IssueTracker"]).include?(tracker_type) |
75 | @app.issue_tracker = tracker_type.constantize.new(params[:app][:issue_tracker_attributes]) | 78 | @app.issue_tracker = tracker_type.constantize.new(params[:app][:issue_tracker_attributes]) |
@@ -77,6 +80,15 @@ class AppsController < InheritedResources::Base | @@ -77,6 +80,15 @@ class AppsController < InheritedResources::Base | ||
77 | end | 80 | end |
78 | end | 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 | def begin_of_association_chain | 92 | def begin_of_association_chain |
81 | # Filter the @apps collection to apps watched by the current user, unless user is an admin. | 93 | # Filter the @apps collection to apps watched by the current user, unless user is an admin. |
82 | # If user is an admin, then no filter is applied, and all apps are shown. | 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,7 +102,7 @@ class AppsController < InheritedResources::Base | ||
90 | def plug_params app | 102 | def plug_params app |
91 | app.watchers.build if app.watchers.none? | 103 | app.watchers.build if app.watchers.none? |
92 | app.issue_tracker = IssueTracker.new unless app.issue_tracker_configured? | 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 | app.copy_attributes_from(params[:copy_attributes_from]) if params[:copy_attributes_from] | 106 | app.copy_attributes_from(params[:copy_attributes_from]) if params[:copy_attributes_from] |
95 | end | 107 | end |
96 | 108 |
app/models/app.rb
@@ -124,6 +124,11 @@ class App | @@ -124,6 +124,11 @@ class App | ||
124 | !!(issue_tracker && issue_tracker.class < IssueTracker && issue_tracker.project_id.present?) | 124 | !!(issue_tracker && issue_tracker.class < IssueTracker && issue_tracker.project_id.present?) |
125 | end | 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 | def notification_recipients | 132 | def notification_recipients |
128 | if notify_all_users | 133 | if notify_all_users |
129 | (User.all.map(&:email).reject(&:blank?) + watchers.map(&:address)).uniq | 134 | (User.all.map(&:email).reject(&:blank?) + watchers.map(&:address)).uniq |