Skip to content

Commit

Permalink
Telemetry permissions and survey answering handling through ui
Browse files Browse the repository at this point in the history
  • Loading branch information
wielas committed Nov 15, 2023
1 parent bf3af66 commit f708dce
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
1 change: 1 addition & 0 deletions flask_monitoringdashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def bind(app, schedule=True, include_dashboard=True):
version,
auth,
reporting,
telemetry
)
import flask_monitoringdashboard.views

Expand Down
3 changes: 2 additions & 1 deletion flask_monitoringdashboard/core/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class TelemetryConfig(object):
def __init__(self):
self.telemetry_initialized = False
self.fmd_user = ''
self.telemetry_consent = True # TODO change to false
self.telemetry_consent = False
self.telemetry_session = 0
self.telemetry_headers = {
'X-Parse-Application-Id': 'zwfDL1t45KjnXSF5ELGQajShV6eJiaKVmRFaQjUb',
'X-Parse-REST-API-Key': 'Kr9nhaAKx04hJypCJzz5BziqbKf9Yq5Q7HsWDpI9',
Expand Down
13 changes: 8 additions & 5 deletions flask_monitoringdashboard/core/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ def initialize_telemetry_session(session):
telemetry_user.last_accessed = datetime.datetime.utcnow()
session.commit()

# save the telemetry_config
# check if telemetry's been agreed on
telemetry_config.telemetry_consent = True if telemetry_user.monitoring_consent == 3 else False

# save the telemetry_config for quick access
telemetry_config.fmd_user = telemetry_user.id
# telemetry_config.telemetry_consent = True if telemetry_user.monitoring_consent == 3 else False # TODO uncomment
telemetry_config.telemetry_initialized = True
telemetry_config.telemetry_session = telemetry_user.times_accessed

# collect user data
endpoints = session.query(Endpoint.name).all()
Expand All @@ -52,8 +55,8 @@ def initialize_telemetry_session(session):

data = {'endpoints': no_of_endpoints,
'blueprints': no_of_blueprints,
'time_accessed': telemetry_user.last_accessed.strftime('%Y-%m-%d %H:%M:%S'),
'session_nr': telemetry_user.times_accessed}
'time_accessed': telemetry_user.last_accessed.strftime('%Y-%m-%d %H:%M:%S')
}

# post user data
post_to_back('UserSession', **data)
Expand All @@ -73,7 +76,7 @@ def post_to_back(class_name='Endpoints', **kwargs):
back4app_endpoint = f'https://parseapi.back4app.com/classes/{class_name}'

headers = telemetry_config.telemetry_headers
data = {'fmd_id': telemetry_config.fmd_user}
data = {'fmd_id': telemetry_config.fmd_user, 'session': telemetry_config.telemetry_session}

for key, value in kwargs.items():
data[key] = value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function SurveyController($scope, $http, $sce) {

// Fetches the survey from database
$scope.fetchSurveyFilled = function () {
$http.post('/dashboard/get_is_survey_filled')
$http.get('/dashboard/telemetry/get_is_survey_filled')
.then(function (response) {
$scope.surveyCompleted = response.data.is_survey_filled;
}, function (error) {
Expand All @@ -41,7 +41,7 @@ export function SurveyController($scope, $http, $sce) {

// Mark survey as filled in database
$scope.surveyFilled = function () {
$http.post('/dashboard/survey_has_been_filled')
$http.get('/dashboard/telemetry/survey_has_been_filled')
.then(function (response) {
}, function (error) {
console.error('Error:', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function TelemetryController($scope, $http) {
$scope.followUpShow = false;

$scope.fetchTelemetryConsent = function () {
$http.post(`/dashboard/get_is_telemetry_answered`)
$http.get(`/dashboard/telemetry/get_is_telemetry_answered`)
.then(function (response) {
$scope.telemetryShow = !response.data.is_telemetry_answered;
}, function (error) {
Expand All @@ -24,6 +24,7 @@ export function TelemetryController($scope, $http) {
});
};


$scope.reasons = {
privacy: false,
performance: false,
Expand Down Expand Up @@ -58,7 +59,6 @@ export function TelemetryController($scope, $http) {
}
$http.post('https://parseapi.back4app.com/classes/FollowUp', { reasons: feedback }, config)
.then(function (response) {
console.log('Feedback sent:', response.data);
}, function (error) {
console.error('Error sending feedback:', error);
});
Expand Down
4 changes: 2 additions & 2 deletions flask_monitoringdashboard/static/js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions flask_monitoringdashboard/views/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
from flask_monitoringdashboard.database import session_scope


@blueprint.route('/api/telemetry/accept_telemetry_consent', methods=['GET', 'POST'])
@blueprint.route('/telemetry/accept_telemetry_consent', methods=['POST'])
def accept_telemetry_consent():

consent = request.form.get('consent')
with session_scope() as session:
try:
print('TELEMETRY CONSENT')
telemetry_user = get_telemetry_user(session)
data = request.get_json()

if 'consent' in data and isinstance(data['consent'], bool) and data['consent']: # if True then agreed
consent = request.form.get('consent')
# {'consent': 'true'}
if consent == 'true': # if True then agreed
print('consent true')
telemetry_user.monitoring_consent = 3 # agree to monitoring
telemetry_config.telemetry_consent = True

else:
print('consent false')
telemetry_user.monitoring_consent = 2 # reject monitoring

session.commit()
Expand All @@ -27,16 +30,16 @@ def accept_telemetry_consent():
print('error committing telemetry consent to database', e)
session.rollback()

# Return no content
return '', 204
# Return no content
return '', 204


@blueprint.route('/api/telemetry/survey_has_been_filled', methods=['POST'])
@blueprint.route('/telemetry/survey_has_been_filled', methods=['GET'])
def survey_has_been_filled():
with session_scope() as session:
try:
telemetry_user = get_telemetry_user(session)
telemetry_user.survey_filled = True
telemetry_user.survey_filled = 3
session.commit()

except SQLAlchemyError as e:
Expand All @@ -47,17 +50,15 @@ def survey_has_been_filled():
return '', 204


@blueprint.route('/api/telemetry/get_is_telemetry_answered', methods=['GET', 'POST'])
@secure
@blueprint.route('/telemetry/get_is_telemetry_answered', methods=['GET'])
def get_is_telemetry_answered():
with session_scope() as session:
print('IS TELEMETRY ANSWERED')
telemetry_user = get_telemetry_user(session)
res = True if telemetry_user.monitoring_consent in (2, 3) else False
res = True if telemetry_user.monitoring_consent == 3 else False
return {'is_telemetry_answered': res}


@blueprint.route('/api/telemetry/get_is_survey_filled', methods=['POST'])
@blueprint.route('/telemetry/get_is_survey_filled', methods=['GET'])
def get_is_survey_filled():
with session_scope() as session:
telemetry_user = get_telemetry_user(session)
Expand Down

0 comments on commit f708dce

Please sign in to comment.