Commit e5f41197 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Simplifica y mejora bloqueo de Task a invitados

En lugar de pisar métodos a lo bestia, se utiliza la función de
predicados de suscripciones de Mediator, para omitir la ejecución de
los callback cuando le llega una publicación y el usuario no se ha
identificado.
parent c42791fc
Loading
Loading
Loading
Loading
+0 −58
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "src/util/Credentials"
	, "src/util/GuestChecker"
], function(
	declare
	, lang
	, aspect
	, Credentials
	, GuestChecker
){
	return declare(null, {
		//	summary:
		//		Extension de _Module.
		//	description:
		//

		constructor: function(args) {

			aspect.before(this, "_setSubscription", lang.hitch(this, this._setSubscriptionChecker));
			aspect.before(this, "_setPublication", lang.hitch(this, this._setPublicationChecker));
		},

		_setSubscriptionChecker: function(subscription) {

			// TODO esta manera de bloquear acciones a los invitados es un poco chapucera, por ahora se permite
			// pasar a 'destroy', pero habrá que replantearlo para hacerlo bien
			if (Credentials.get("userRole") === "ROLE_GUEST" &&
				subscription.channel.indexOf(this.ownChannel) !== -1 &&
				subscription.channel.indexOf('destroy') === -1) {

				subscription.callback = "_subAuthFailed";
			}

			return [subscription];
		},

		_setPublicationChecker: function(publication) {

			if (Credentials.get("userRole") === "ROLE_GUEST") {
				publication.callback = "_pubAuthFailed";
			}

			return [publication];
		},

		_subAuthFailed: function() {

			GuestChecker.protectFromGuests();
		},

		_pubAuthFailed: function() {

		}
	});
});
+13 −0
Original line number Diff line number Diff line
define([
	'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'src/util/Credentials'
	, 'src/util/GuestChecker'
], function(
	declare
	, lang
	, Credentials
	, GuestChecker
) {

	return declare(null, {
@@ -125,6 +129,15 @@ define([
		_chkSuccessfulStatus: function(status) {

			return status >= 200 && status < 400;
		},

		_chkUserIsNotGuest: function() {

			var userIsGuest = Credentials.get("userRole") === "ROLE_GUEST";

			userIsGuest && GuestChecker.protectFromGuests();

			return !userIsGuest;
		}
	});
});
+22 −10
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "src/component/base/_AuthFirewall"
	, "src/component/base/_Module"
	, "src/component/base/_Store"
	, "src/component/base/_Selection"
@@ -11,7 +10,6 @@ define([
], function(
	declare
	, lang
	, _AuthFirewall
	, _Module
	, _Store
	, _Selection
@@ -19,7 +17,7 @@ define([
	, _Worms
	, Credentials
){
	return declare([_Module, _AuthFirewall, _Store, _Selection, _Report, _Worms], {
	return declare([_Module, _Store, _Selection, _Report, _Worms], {
		//	Summary:
		//		Módulo para gestionar la ejecución de tareas en segundo plano via sockets

@@ -57,12 +55,12 @@ define([
			};

			lang.mixin(this, this.config, args);

			this.baseSubscriptionsTarget = '/user/' + Credentials.get("userId");
		},

		_setConfigurations: function() {

			this.baseSubscriptionsTarget = '/user/' + Credentials.get("userId");

			this.socketChannels = this._merge([{
				getTasks: {
					baseTarget: this.baseSubscriptionsTarget + this.baseTarget + 'status',
@@ -73,21 +71,28 @@ define([

		_defineSubscriptions: function () {

			var commonOpts = this._getSubCommonOpts();

			this.subscriptionsConfig.push({
				channel : this.getChannel("REFRESH_STATUS"),
				callback: "_subRefreshStatus"
				callback: "_subRefreshStatus",
				options: commonOpts
			},{
				channel: this.getChannel("SOCKET_CONNECT"),
				callback: "_subSocketConnect"
				callback: "_subSocketConnect",
				options: commonOpts
			},{
				channel : this.getChannel("BUTTON_EVENT"),
				callback: "_subButtonEvent"
				callback: "_subButtonEvent",
				options: commonOpts
			},{
				channel : this.getChannel("REMOVE"),
				callback: "_subRemove"
				callback: "_subRemove",
				options: commonOpts
			},{
				channel : this.getChannel("ALL_TASK"),
				callback: "_subAllTask"
				callback: "_subAllTask",
				options: commonOpts
			});
		},

@@ -102,6 +107,13 @@ define([
			});
		},

		_getSubCommonOpts: function() {

			return {
				predicate: lang.hitch(this, this._chkUserIsNotGuest)
			};
		},

		_subRefreshStatus: function() {

			this._allTaskSocket({
+14 −11
Original line number Diff line number Diff line
define([
	'src/redmicConfig'
	, "dojo/_base/declare"
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "src/util/Credentials"
	, 'src/redmicConfig'
], function(
	redmicConfig
	, declare
	declare
	, lang
	, aspect
	, Credentials
	, redmicConfig
){
	return declare(null, {
		//	Summary:
@@ -30,8 +28,6 @@ define([

			lang.mixin(this, this.config, args);

			this.ingestBaseTarget = this.baseTarget + "ingest/";

			aspect.before(this, "_afterSetConfigurations", lang.hitch(this, this._setIngestDataConfigurations));
			aspect.after(this, "_defineSubscriptions", lang.hitch(this, this._defineIngestDataSubscriptions));
			aspect.before(this, "_mixEventsAndActions", lang.hitch(this, this._mixIngestDataEventsAndActions));
@@ -39,6 +35,8 @@ define([

		_setIngestDataConfigurations: function() {

			this.ingestBaseTarget = this.baseTarget + "ingest/";

			this.socketChannels = this._merge([{
				ingestStatus: {
					baseTarget: this.baseSubscriptionsTarget + this.ingestBaseTarget + 'status',
@@ -56,15 +54,20 @@ define([

		_defineIngestDataSubscriptions: function () {

			var commonOpts = this._getSubCommonOpts();

			this.subscriptionsConfig.push({
				channel : this.getChannel("INGEST_DATA_RUN"),
				callback: "_subIngestDataRun"
				callback: "_subIngestDataRun",
				options: commonOpts
			},{
				channel : this.getChannel("INGEST_DATA_RESUME"),
				callback: "_subIngestDataResume"
				callback: "_subIngestDataResume",
				options: commonOpts
			},{
				channel : this.getChannel("INGEST_DATA_STOP"),
				callback: "_subIngestDataStop"
				callback: "_subIngestDataStop",
				options: commonOpts
			});
		},

+8 −5
Original line number Diff line number Diff line
define([
	'alertify/alertify.min'
	, 'src/redmicConfig'
	, "dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, 'src/redmicConfig'
	, "src/util/Credentials"
], function(
	alertify
	, redmicConfig
	, declare
	, lang
	, aspect
	, redmicConfig
	, Credentials
){
	return declare(null, {
@@ -32,8 +32,6 @@ define([

			lang.mixin(this, this.config, args);

			this.reportBaseTarget = this.baseTarget + "report/";

			aspect.before(this, "_afterSetConfigurations", lang.hitch(this, this._setReportConfigurations));
			aspect.after(this, "_defineSubscriptions", lang.hitch(this, this._defineReportSubscriptions));
			aspect.before(this, "_mixEventsAndActions", lang.hitch(this, this._mixReportEventsAndActions));
@@ -41,6 +39,8 @@ define([

		_setReportConfigurations: function() {

			this.reportBaseTarget = this.baseTarget + "report/";

			this.socketChannels = this._merge([{
				reportStatus: {
					baseTarget: this.baseSubscriptionsTarget + this.reportBaseTarget + 'status',
@@ -59,9 +59,12 @@ define([

		_defineReportSubscriptions: function () {

			var commonOpts = this._getSubCommonOpts();

			this.subscriptionsConfig.push({
				channel : this.getChannel("GET_REPORT"),
				callback: "_subGetReport"
				callback: "_subGetReport",
				options: commonOpts
			});
		},

Loading