Add applications information page

This commit is contained in:
augier 2015-08-01 15:27:40 +02:00 committed by theworldbright
parent 65c40f236e
commit 308170f691
8 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,9 @@
class UserApplicationsController < ApplicationController
before_action :authenticate_user!
def show
respond_to do |format|
format.all { @user_apps = UserApplicationsPresenter.new current_user }
end
end
end

View file

@ -19,6 +19,10 @@ module Api
self.client_secret = SecureRandom.hex(32)
end
def image_uri
self.logo_uri ? self.logo_uri : "branding/logos/asterisk.png"
end
class << self
def available_response_types
["id_token", "id_token token", "code"]

View file

@ -0,0 +1,34 @@
class UserApplicationsPresenter
def initialize(user)
@current_user = user
end
def user_applications
@applications ||= @current_user.o_auth_applications.each_with_object([]) do |app, array|
array << app_as_json(app)
end
end
def applications_count
user_applications.size
end
def applications?
applications_count > 0
end
private
def app_as_json(application)
{
name: application.client_name,
image: application.image_uri,
autorizations: find_scopes(application)
}
end
def find_scopes(application)
Api::OpenidConnect::Authorization.find_by_client_id_and_user(
application.client_id, @current_user).scopes
end
end

View file

@ -6,3 +6,4 @@
%li{class: current_page?(edit_user_path) && "active"}= link_to t("account"), edit_user_path
%li{class: current_page?(privacy_settings_path) && "active"}= link_to t("privacy"), privacy_settings_path
%li{class: current_page?(services_path) && "active"}= link_to t("_services"), services_path
%li{class: current_page?(user_applications_path) && 'active'}= link_to t("_applications"), user_applications_path

View file

@ -0,0 +1,21 @@
- if @user_apps.applications?
%ul.list-group
- @user_apps.user_applications.each do |app|
%li.list-group-item
.row
.col-xs-2
= image_tag app[:image], class: "img-responsive"
.col-xs-10
- if app[:autorizations].count > 0
%h4="#{app[:name]} #{t("user_applications.show.access")}"
%ul
- app[:autorizations].each do |autorization|
%li=autorization.name
- else
.well
=t("user_applications.show.no_requirement")
- else
.well
%h4
= t("user_applications.show.no_applications")

View file

@ -0,0 +1,17 @@
- content_for :page_title do
= t(".edit_applications")
.container-fluid
= render "shared/settings_nav"
.container-fluid
.row
.col-lg-8.col-lg-offset-2
%h3= t(".title")
%p.visible-sm-block.visible-xs-block
= t(".applications_explanation")
.row
.col-md-7
= render "add_remove_applications"
.col-md-5
%p.hidden-sm.hidden-xs
= t(".applications_explanation")

View file

@ -1476,3 +1476,12 @@ en:
disabled: "Not available"
open: "Open"
closed: "Closed"
user_applications:
show:
edit_applications: "Applications"
title: "Your installed applications"
no_applications: "You have no authorized application for now"
access: "is authorized to access to:"
no_requirement: "This application requires no autorizations"
applications_explanation: "Here are listed the applications to which you autorized the access to your profile informations"

View file

@ -254,4 +254,6 @@ Diaspora::Application.routes.draw do
get "user_info", to: "user_info#show"
end
end
resource :user_applications, only: [:show]
end