Skip to content

Commit

Permalink
[webui][api] RSS Feed for users notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Moises Deniz Aleman authored and hennevogel committed Jun 29, 2017
1 parent 7eb8166 commit 04e26cb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/api/app/controllers/webui/feeds_controller.rb
Expand Up @@ -40,4 +40,11 @@ def commits
@commits = @commits.where(["datetime <= ?", @finish]) unless @finish.nil?
@commits = @commits.order("datetime desc")
end

def notifications
@host = ::Configuration.obs_url
@configuration = ::Configuration.first
@user = User.current
@notifications = User.current.combined_rss_feed_items
end
end
6 changes: 6 additions & 0 deletions src/api/app/models/user.rb
Expand Up @@ -904,6 +904,12 @@ def display_name
address.format
end

def combined_rss_feed_items
Notification::RssFeedItem.where(subscriber: self).or(
Notification::RssFeedItem.where(subscriber: groups)
).order(created_at: :desc, id: :desc).limit(Notification::RssFeedItem::MAX_ITEMS_PER_USER)
end

private

def can_modify_project_internal(project, ignore_lock)
Expand Down
21 changes: 21 additions & 0 deletions src/api/app/views/webui/feeds/notifications.rss.builder
@@ -0,0 +1,21 @@
xml.rss version: '2.0' do
xml.channel do
xml.title "#{@user.realname}'s (#{@user.login}) notifications"
xml.description "Event's notifications from #{@configuration['title']}"
xml.link url_for only_path: false, controller: 'main', action: 'index'
xml.language "en"
xml.pubDate Time.now
xml.generator @configuration['title']

@notifications.each do |notification|
xml.item do
xml.title notification.event_type
xml.description notification.event_payload
xml.category "#{notification.event_type}/#{notification.subscription_receiver_role}"
xml.pubDate notification.created_at
xml.author "#{@configuration['title']}"
xml.link url_for only_path: false, controller: 'main', action: 'index'
end
end
end
end
1 change: 1 addition & 0 deletions src/api/config/routes.rb
Expand Up @@ -58,6 +58,7 @@ def self.public_or_about_path?(request)
get 'main/news' => :news, as: :news_feed
get 'main/latest_updates' => :latest_updates, as: :latest_updates_feed
get 'project/latest_commits/:project' => :commits, defaults: { format: 'atom' }, constraints: cons, as: 'commits_feed'
get 'user/feed' => :notifications, defaults: { format: 'rss' }, as: :user_rss_notifications
end

resources :attribs, constraints: cons, only: [:create, :update, :destroy], controller: 'webui/attribute' do
Expand Down

0 comments on commit 04e26cb

Please sign in to comment.