• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

simukappu / activity_notification / 12735624472

12 Jan 2025 05:24PM UTC coverage: 100.0%. Remained the same
12735624472

push

travis-ci

simukappu
Update Ruby versions for test

3432 of 3432 relevant lines covered (100.0%)

2130.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/app/controllers/activity_notification/notifications_api_controller.rb
1
module ActivityNotification
24✔
2
  # Controller to manage notifications API.
3
  class NotificationsApiController < NotificationsController
24✔
4
    # Include Swagger API reference
5
    include Swagger::NotificationsApi
24✔
6
    # Include CommonApiController to select target and define common methods
7
    include CommonApiController
24✔
8
    protect_from_forgery except: [:open_all]
24✔
9
    rescue_from ActivityNotification::NotifiableNotFoundError, with: :render_notifiable_not_found
24✔
10

11
    # Returns notification index of the target.
12
    #
13
    # GET /:target_type/:target_id/notifications
14
    # @overload index(params)
15
    #   @param [Hash] params Request parameter options for notification index
16
    #   @option params [String] :filter                 (nil)     Filter option to load notification index by their status (Nothing as auto, 'opened' or 'unopened')
17
    #   @option params [String] :limit                  (nil)     Maximum number of notifications to return
18
    #   @option params [String] :reverse                ('false') Whether notification index will be ordered as earliest first
19
    #   @option params [String] :without_grouping       ('false') Whether notification index will include group members
20
    #   @option params [String] :with_group_members     ('false') Whether notification index will include group members
21
    #   @option params [String] :filtered_by_type       (nil)     Notifiable type to filter notification index
22
    #   @option params [String] :filtered_by_group_type (nil)     Group type to filter notification index, valid with :filtered_by_group_id
23
    #   @option params [String] :filtered_by_group_id   (nil)     Group instance ID to filter notification index, valid with :filtered_by_group_type
24
    #   @option params [String] :filtered_by_key        (nil)     Key of notifications to filter notification index
25
    #   @option params [String] :later_than             (nil)     ISO 8601 format time to filter notification index later than specified time
26
    #   @option params [String] :earlier_than           (nil)     ISO 8601 format time to filter notification index earlier than specified time
27
    #   @return [JSON] count: number of notification index records, notifications: notification index
28
    def index
24✔
29
      super
384✔
30
      render json: {
384✔
31
        count: @notifications.size, 
32
        notifications: @notifications.as_json(notification_json_options)
33
      }
34
    end
35

36
    # Opens all notifications of the target.
37
    #
38
    # POST /:target_type/:target_id/notifications/open_all
39
    # @overload open_all(params)
40
    #   @param [Hash] params Request parameters
41
    #   @option params [String] :filtered_by_type       (nil)     Notifiable type to filter notification index
42
    #   @option params [String] :filtered_by_group_type (nil)     Group type to filter notification index, valid with :filtered_by_group_id
43
    #   @option params [String] :filtered_by_group_id   (nil)     Group instance ID to filter notification index, valid with :filtered_by_group_type
44
    #   @option params [String] :filtered_by_key        (nil)     Key of notifications to filter notification index
45
    #   @option params [String] :later_than             (nil)     ISO 8601 format time to filter notification index later than specified time
46
    #   @option params [String] :earlier_than           (nil)     ISO 8601 format time to filter notification index earlier than specified time
47
    #   @return [JSON] count: number of opened notification records, notifications: opened notifications
48
    def open_all
24✔
49
      super
264✔
50
      render json: {
264✔
51
        count: @opened_notifications.size,
52
        notifications: @opened_notifications.as_json(notification_json_options)
53
      }
54
    end
55
  
56
    # Returns a single notification.
57
    #
58
    # GET /:target_type/:target_id/notifications/:id
59
    # @overload show(params)
60
    #   @param [Hash] params Request parameters
61
    #   @return [JSON] Found single notification
62
    def show
24✔
63
      super
144✔
64
      render json: notification_json
144✔
65
    end
66
  
67
    # Deletes a notification.
68
    #
69
    # DELETE /:target_type/:target_id/notifications/:id
70
    # @overload destroy(params)
71
    #   @param [Hash] params Request parameters
72
    #   @return [JSON] 204 No Content
73
    def destroy
24✔
74
      super
96✔
75
      head 204
96✔
76
    end
77
  
78
    # Opens a notification.
79
    #
80
    # PUT /:target_type/:target_id/notifications/:id/open
81
    # @overload open(params)
82
    #   @param [Hash] params Request parameters
83
    #   @option params [String] :move ('false') Whether it redirects to notifiable_path after the notification is opened
84
    #   @return [JSON] count: number of opened notification records, notification: opened notification
85
    def open
24✔
86
      super
240✔
87
      unless params[:move].to_s.to_boolean(false)
240✔
88
        render json: {
120✔
89
          count: @opened_notifications_count,
90
          notification: notification_json
91
        }
92
      end
93
    end
94

95
    # Moves to notifiable_path of the notification.
96
    #
97
    # GET /:target_type/:target_id/notifications/:id/move
98
    # @overload open(params)
99
    #   @param [Hash] params Request parameters
100
    #   @option params [String] :open ('false') Whether the notification will be opened
101
    #   @return [JSON] location: notifiable path, count: number of opened notification records, notification: specified notification
102
    def move
24✔
103
      super
288✔
104
      render status: 302, location: @notification.notifiable_path, json: {
288✔
105
        location: @notification.notifiable_path,
106
        count: (@opened_notifications_count || 0),
288✔
107
        notification: notification_json
108
      }
109
    end
110

111
    protected
24✔
112

113
      # Returns options for notification JSON
114
      # @api protected
115
      def notification_json_options
24✔
116
        {
117
          include: {
1,200✔
118
            target: { methods: [:printable_type, :printable_target_name] },
119
            notifiable: { methods: [:printable_type] },
120
            group: { methods: [:printable_type, :printable_group_name] },
121
            notifier: { methods: [:printable_type, :printable_notifier_name] },
122
            group_members: {}
123
          },
124
          methods: [:notifiable_path, :printable_notifiable_name, :group_member_notifier_count, :group_notification_count]
125
        }
126
      end
127

128
      # Returns JSON of @notification
129
      # @api protected
130
      def notification_json
24✔
131
        @notification.as_json(notification_json_options)
552✔
132
      end
133

134
      # Render associated notifiable record not found error with 500 status
135
      # @api protected
136
      # @param [Error] error Error object
137
      # @return [void]
138
      def render_notifiable_not_found(error)
24✔
139
        render status: 500, json: error_response(code: 500, message: "Associated record not found", type: error.message)
48✔
140
      end
141

142
  end
143
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc