From 49d509935284c2f07c8f5cb53a31d5787c6ef7ab Mon Sep 17 00:00:00 2001
From: Vinnie Okada <vokada@mrvinn.com>
Date: Sat, 14 Feb 2015 13:26:08 -0700
Subject: [PATCH] Avoid duplicate application rows

Iterate over authorized applications instead of tokens to avoid multiple
rows for the same authorized app.
---
 app/controllers/profiles_controller.rb    |  3 +++
 app/views/profiles/applications.html.haml | 10 +++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
index f7584c0341..e3e36505f0 100644
--- a/app/controllers/profiles_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -16,6 +16,9 @@ class ProfilesController < ApplicationController
   def applications
     @applications = current_user.oauth_applications
     @authorized_tokens = current_user.oauth_authorized_tokens
+    @authorized_apps = @authorized_tokens.map do |token|
+      token.application
+    end.uniq
   end
 
   def update
diff --git a/app/views/profiles/applications.html.haml b/app/views/profiles/applications.html.haml
index cb24e4a3dd..4b5817e10b 100644
--- a/app/views/profiles/applications.html.haml
+++ b/app/views/profiles/applications.html.haml
@@ -36,12 +36,12 @@
           %th Scope
           %th
       %tbody
-        - @authorized_tokens.each do |token|
-          - application = token.application
-          %tr{:id => "application_#{application.id}"}
-            %td= application.name
+        - @authorized_apps.each do |app|
+          - token = app.authorized_tokens.order('created_at desc').first
+          %tr{:id => "application_#{app.id}"}
+            %td= app.name
             %td= token.created_at
             %td= token.scopes
-            %td= render 'doorkeeper/authorized_applications/delete_form', application: application
+            %td= render 'doorkeeper/authorized_applications/delete_form', application: app
   - else
     %p.light You dont have any authorized applications
-- 
2.30.9