Skip to content

Commit

Permalink
Allow executeGlobalController @W-5679866 (#3973) (#3985)
Browse files Browse the repository at this point in the history
bypass Aura API for internal
  • Loading branch information
byao authored and GitHub Enterprise committed Dec 8, 2018
1 parent 74e7f47 commit 455476a
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2013 salesforce.com, inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.auraframework.components.test.java.controller;

import org.auraframework.annotations.Annotations.ServiceComponent;
import org.auraframework.ds.servicecomponent.GlobalController;
import org.auraframework.system.Annotations.AuraEnabled;
import org.auraframework.system.Annotations.Controller;
import org.auraframework.system.Annotations.Key;

@ServiceComponent
@Controller(internal = true)
public class TestInternalGlobalController implements GlobalController {
@Override
public String getQualifiedName() {
return "aura://TestInternalGlobalController";
}

@AuraEnabled
public String getString(@Key("param") String param) {
return param;
}
}
16 changes: 12 additions & 4 deletions aura-impl/src/main/resources/aura/modules/AuraExportsInterop.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ Aura.ExportsModule = {
*/
"executeGlobalController": function (endpoint, params, options) {
var hotspot = options && options.hotspot;
var controllerName = 'c.aura://' + endpoint;
var action = $A.get(controllerName);

var controller = 'aura://' + endpoint;
var path = controller.split(".");
var controllerName = path.shift();
var actionName = path.shift();

var controllerDef = $A.componentService.controllerDefRegistry[controllerName];
if (!controllerDef) {
return Promise.reject(new Error('Controller for endpoint ' + endpoint + ' does not exist'));
}

var action = controllerDef.getActionDef(actionName).newInstance();
if (!action) {
return Promise.reject(new Error('Controller for endpoint ' + endpoint + ' is not registered'));
return Promise.reject(new Error('Action of endpoint ' + endpoint + ' is not registered'));
}
action.setParams(params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15715,6 +15715,24 @@ $A.componentService.initControllerDefs([
]
}
]
},
{
"descriptor":"aura://TestInternalGlobalController",
"xs":"I",
"ac":[
{
"n":"getString",
"descriptor":"aura://TestInternalGlobalController/ACTION$getString",
"at":"SERVER",
"rt":"java://java.lang.String",
"pa":[
{
"name":"param",
"type":"java://java.lang.String"
}
]
}
]
}
]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/l/{"mode":"UTEST","app":"#REPLACED#","styleContext":{"c":"other","tokens":["markup://test:fakeTokens2","markup://test:fakeTokens","markup://test:fakeTokens3"],"tuid":"ldNUYpx4rBy4n1fa0xdfoA","cuid":-367192221},"pathPrefix":"","test":"org.auraframework.integration.test.css.StyleContextSerializationTest.testCssUrlWithMultipleAppTokensDefs"}/app.css
/l/{"mode":"UTEST","app":"#REPLACED#","styleContext":{"c":"other","tokens":["markup://test:fakeTokens2","markup://test:fakeTokens","markup://test:fakeTokens3"],"tuid":"xI2f1bx6LvB7LcAPIp0zDw","cuid":-191129207},"pathPrefix":"","test":"org.auraframework.integration.test.css.StyleContextSerializationTest.testCssUrlWithMultipleAppTokensDefs"}/app.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/l/{"mode":"UTEST","app":"#REPLACED#","styleContext":{"c":"other","tokens":["markup://test:fakeTokens"],"tuid":"2gMNlo5Ho_fm4bLrgFUtzg","cuid":-1724347081},"pathPrefix":"","test":"org.auraframework.integration.test.css.StyleContextSerializationTest.testCssUrlWithProvidedTokens"}/app.css
/l/{"mode":"UTEST","app":"#REPLACED#","styleContext":{"c":"other","tokens":["markup://test:fakeTokens"],"tuid":"txGGourOJG2u8zCrmJRI1g","cuid":-1481889961},"pathPrefix":"","test":"org.auraframework.integration.test.css.StyleContextSerializationTest.testCssUrlWithProvidedTokens"}/app.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/l/{"mode":"UTEST","app":"#REPLACED#","styleContext":{"c":"other","tokens":["markup://test:fakeTokensWithMapProvider","markup://test:fakeTokens3"],"tuid":"-mm7cEKiGNf0vxGk1U0Egw","cuid":-1792234906},"pathPrefix":"","test":"org.auraframework.integration.test.css.StyleContextSerializationTest.testSerializeWithMapProvidedTokens"}/app.css
/l/{"mode":"UTEST","app":"#REPLACED#","styleContext":{"c":"other","tokens":["markup://test:fakeTokensWithMapProvider","markup://test:fakeTokens3"],"tuid":"R7_RmOUWs96kda4dlzVsIg","cuid":-1758276631},"pathPrefix":"","test":"org.auraframework.integration.test.css.StyleContextSerializationTest.testSerializeWithMapProvidedTokens"}/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
browsers : [ 'GOOGLECHROME' ],
test: [
function (cmp) {
var target = cmp.helper.exports.executedGlobalControllerWithCustomException();
target.catch(function(err) {
return cmp.helper.exports.executedGlobalControllerWithCustomException().catch(function(err) {
$A.test.assertEquals("testCustomMessage", err.message);
});
}
]
},
testExecuteGlobalControllerNoAccessError: {
browsers : [ 'GOOGLECHROME' ],
test: [
function (cmp) {
var expected = "woot";
return cmp.helper.exports.executeTestInternalGlobalController(expected).then(function(actual) {
$A.test.assertEquals(expected, actual, "Internal controller response does not match.");
}).catch(function() {
$A.test.fail("Calling internal global controller from executeGlobalController should not fail")
});
}
]
}
})
4 changes: 4 additions & 0 deletions aura-modules/src/test/modules/moduletest/exports/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ export function executedGlobalControllerWithCustomException() {
.catch(err => {
throw new Error(err['data']['customMessage']); // eslint-disable-line dot-notation
});
}

export function executeTestInternalGlobalController(param) {
return executeGlobalController("TestInternalGlobalController.getString", { param: param});
}

0 comments on commit 455476a

Please sign in to comment.