Skip to content

Commit

Permalink
Merge branch 'integration' into yashu-sso-link-accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
lagoan authored Sep 5, 2024
2 parents 28d4e33 + bc836bf commit 1fb6100
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 149 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@

- Implemented openid_connection SSO with CILogon

- Create GET "/api/ca_dashboard/stats" endpoint to fetch Plan, User, and Org-related statistics [#852](https://github.com/portagenetwork/roadmap/pull/852)

### Changed

- Update Favicons and Associated HTML Code [#873](https://github.com/portagenetwork/roadmap/pull/873)

- Drop Sessions Table and Delete `lib/tasks/sessions.rake` [#859](https://github.com/portagenetwork/roadmap/pull/859)

### Fixed

- Fix triggering and title of autosent email when a user's admin privileges are changed [#858](https://github.com/portagenetwork/roadmap/pull/858)

- Fix flaky tests / Optimize Checking Of `plan.title` Within `spec/features/plans/exports_spec.rb` [#871](https://github.com/portagenetwork/roadmap/pull/871)

## [4.1.1+portage-4.1.3] - 2024-08-08

### Changed

- Bump rexml from 3.2.8 to 3.3.3 [#839](https://github.com/portagenetwork/roadmap/pull/839)
Expand Down
59 changes: 59 additions & 0 deletions app/controllers/api/ca_dashboard/stats_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

module Api
module CaDashboard
# Handles CRUD operations for "/api/ca_dashboard/stats"
class StatsController < Api::V1::BaseApiController
# Allow public access / bypass JWT authentication via "POST /api/v1/authenticate"
skip_before_action :authorize_request, only: [:index]

# GET /api/ca_dashboard/stats
def index
base_hash = {
'plans' => Plan.all,
'orgs' => Org.where(managed: true).all,
'users' => User.all
}
@totals = {
'all_time' => all_time_counts(base_hash),
'last_30_days' => last_30_days_counts(base_hash)
}
begin
@totals['custom_range'] = custom_range_counts(base_hash) if date_params_present?
render 'api/ca_dashboard/stats/index', status: :ok
rescue ArgumentError
error_msg = _('Invalid date format. please use YYYY-MM-DD when supplying `start` or `end` params.')
render_error(errors: [error_msg], status: :bad_request)
end
end

private

def all_time_counts(base_hash)
base_hash.transform_values(&:count)
end

def last_30_days_counts(base_hash)
base_hash.transform_values do |scope|
scope.where('created_at >= ?', 30.days.ago).count
end
end

def custom_range_counts(base_hash)
start_date = parse_date(params[:start])
end_date = parse_date(params[:end])
base_hash.transform_values do |scope|
scope.where(created_at: start_date..end_date).count
end
end

def date_params_present?
params[:start].present? || params[:end].present?
end

def parse_date(date_string)
Date.strptime(date_string, '%Y-%m-%d') if date_string.present?
end
end
end
end
6 changes: 2 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ def admin_update_permissions
end
elsif perms.include? perm
@user.perms << perm
if perm.id == Perm.use_api.id
@user.keep_or_generate_token!
privileges_changed = true
end
@user.keep_or_generate_token! if perm.id == Perm.use_api.id
privileges_changed = true
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def admin_privileges(user)

I18n.with_locale I18n.locale do
mail(to: user.email,
subject: format(_('Administrator privileges granted in %{tool_name}'),
subject: format(_('Administrator privileges updated in %{tool_name}'),
tool_name: tool_name))
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/views/api/ca_dashboard/stats/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

json.partial! 'api/v1/standard_response'
json.stats do
json.totals @totals
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<title><%= content_for?(:title) ? yield(:title) : _('%{application_name}') % { :application_name => ApplicationService.application_name } %>
</title>

<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@
resources :plans, only: %i[create show index]
resources :templates, only: [:index]
end

namespace :ca_dashboard do
resources :stats, only: [:index]
end
end

namespace :paginable do
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20240820190548_drop_sessions_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class DropSessionsTable < ActiveRecord::Migration[6.1]
def up
drop_table :sessions
end

def down
# rollback will the execute the initial migration code written to create the sessions table
require Rails.root.join('db/migrate/20181024120747_add_sessions_table.rb')
AddSessionsTable.new.change
end
end
Loading

0 comments on commit 1fb6100

Please sign in to comment.