diff --git a/plugins/environment_notification/lib/notification_manager.rb b/plugins/environment_notification/lib/notification_manager.rb new file mode 100644 index 0000000..e55e622 --- /dev/null +++ b/plugins/environment_notification/lib/notification_manager.rb @@ -0,0 +1,64 @@ +module NotificationManager + + def index + @notifications = target.environment_notifications.order('updated_at DESC') + end + + def new + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new + if request.post? + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new(params[:notifications]) + @notification.message = @notification.message.html_safe + @notification.target = target + if @notification.save + session[:notice] = _("Notification successfully created") + redirect_to :action => :index + else + session[:notice] = _("Notification couldn't be created") + end + end + end + + def destroy + if request.delete? + notification = target.environment_notifications.find_by_id(params[:id]) + if notification && notification.destroy + session[:notice] = _('The notification was deleted.') + else + session[:notice] = _('Could not remove the notification') + end + end + redirect_to :action => :index + end + + def edit + @notification = target.environment_notifications.find_by_id(params[:id]) + if request.post? + if @notification.update_attributes(params[:notifications]) + session[:notice] = _('The notification was edited.') + else + session[:notice] = _('Could not edit the notification.') + end + redirect_to :action => :index + end + end + + def change_status + @notification = target.environment_notifications.find_by_id(params[:id]) + + @notification.active = !@notification.active + + if @notification.save! + session[:notice] = _('The status of the notification was changed.') + else + session[:notice] = _('Could not change the status of the notification.') + end + + redirect_to :action => :index + end + + protected + def admin_required + redirect_to :root unless current_user.person.is_admin? + end +end -- libgit2 0.21.2