1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

[bug] when a new account is created through the sign-up modal, the role is not reported in the StatisticProfile (#196)

Also: if a member was deleted the /api/members/mapping will raise an error
This commit is contained in:
Sylvain 2020-05-18 16:23:53 +02:00
parent 0cd5061852
commit fdc2f60ff5
7 changed files with 36 additions and 11 deletions

View File

@ -3,11 +3,14 @@
- Upgraded to ruby 2.6.5
- Prevent admins from leaving their dedicated group
- Faraday was downgraded from 1.0 to 0.17 for better compatibility with elasticsearch-ruby 5 (#205 #196)
- Added an option to allow usage in production without HTTPS
- Added [an option](doc/environment.md#ALLOW_INSECURE_HTTP) to allow usage in production without HTTPS
- Now using node.js instead of therubyracer for building javascript assets
- Fix a bug: when an admin logs on the subscription page, his view is broken
- Fix a bug: admin's members list shows the same members multiple times
- Fix a bug: when a new account is created through the sign-up modal, the role is not reported in the StatisticProfile (#196)
- Fix a security issue: updated actionpack-page_caching from 1.1.0 to 1.2.2 to fix [CVE-2020-8159](https://nvd.nist.gov/vuln/detail/CVE-2020-8159)
- [TODO DEPLOY] `rails fablab:fix:role_in_statistic_profile`
- [TODO DEPLOY] `rails fablab:es:generate_stats[2019-06-13]` (run after the command above!)
## v4.4.1 2020 May 12

View File

@ -450,9 +450,9 @@ Application.Controllers.controller('ApplicationController', ['$rootScope', '$sco
return $state.go(toState, toParams);
}
}, function (reason) {
// authentication did not ended successfully
// authentication did not end successfully
if (reason === 'signup') {
// open signup modal
// open sign-up modal
$scope.signup();
} else if (reason === 'resetPassword') {
// open the 'reset password' modal

View File

@ -9,7 +9,7 @@ class User < ApplicationRecord
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable,
:confirmable
rolify
rolify after_add: :update_statistic_profile, after_remove: :update_statistic_profile
# enable OmniAuth authentication only if needed
devise :omniauthable, omniauth_providers: [AuthProvider.active.strategy_name.to_sym] unless
@ -431,12 +431,14 @@ class User < ApplicationRecord
)
end
# will update the statistic_profile after a group switch. Updating the role is not supported
def update_statistic_profile
# will update the statistic_profile after a group switch
# Rolify callbacks will call this function with an argument unused here
def update_statistic_profile(_param = nil)
raise NoProfileError if statistic_profile.nil?
statistic_profile.update_attributes(
group_id: group_id
group_id: group_id,
role_id: roles.first.id
)
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
@members.each do |member|
json.set! member.id, member.profile.full_name
json.set! member.id, member&.profile&.full_name
end

View File

@ -265,10 +265,11 @@ You can change this behavior by setting this variable to one of the following va
- "once" to keep the default behavior.
- "session" to display the tours each time you reopen the application.
- "manual" to prevent displaying the tours automatically; you'll still be able to trigger them by pressing the F1 key.
<a name="ALLOW_INSECURE_HTTP"></a>
ALLOW_INSECURE_HTTP
In production and staging environments, the session cookie won't be sent to the server unless through the HTTPS protocol.
If you're using Fab-manager on a non-public network or for testing purposes, you can disable this behavior by setting this variable to `true`.
Please, ensure you know what you're doing, as this can lead to serious security issues.

View File

@ -166,9 +166,10 @@ namespace :fablab do
desc '(re)generate statistics in ElasticSearch for the past period. Use 0 to generate for today'
task :generate_stats, [:period] => :environment do |_task, args|
raise 'FATAL ERROR: You must pass a number of days (=> past period) to generate statistics on' unless args.period
raise 'FATAL ERROR: You must pass a number of days (=> past period) OR a date to generate statistics' unless args.period
days = args.period.to_i
days = date_to_days(args.period)
puts "\n==> generating statistics for the last #{days} days <==\n"
if days.zero?
StatisticService.new.generate_statistic(start_date: DateTime.current.beginning_of_day, end_date: DateTime.current.end_of_day)
else
@ -178,5 +179,11 @@ namespace :fablab do
end
end
def date_to_days(value)
date = Date.parse(value.to_s)
(DateTime.current.to_date - date).to_i
rescue ArgumentError
value.to_i
end
end
end

View File

@ -164,5 +164,15 @@ namespace :fablab do
end
end
end
desc '[release 4.4.2] add missing role to StatisticProfile'
task role_in_statistic_profile: :environment do
puts "Fixing #{StatisticProfile.where(role_id: nil).count} bugged profiles...\n"
StatisticProfile.where(role_id: nil).each do |sp|
role_id = sp&.user&.roles&.first&.id
sp.role_id = role_id
sp.save!
end
end
end
end