AnsweredAssumed Answered

Ocultar o deshabilitar 'Mis ficheros', 'Ficheros compartidos',.... cuando los usuarios no sean administrador

Question asked by fjsobrino on Sep 15, 2014
Latest reply on Oct 23, 2014 by mc2014

Buenos días,

Soy novato de alfresco y también estoy aprendiendo javascript. Quiero ocultar o deshabitilar "Mis ficheros",… cuando los usuarios no sean administradores. Bueno estaba investigando sobre el fichero de share-header.get.js de alfresco V 4.2.f, estaba buscando varios foros sobre ese tema y he encontrado algunos:

https://forums.alfresco.com/comment/125692#comment-125692

http://blogs.alfresco.com/wp/developer/2013/09/16/customizing-the-share-header-part-3/

https://issues.alfresco.com/jira/browse/ALF-19930

https://forums.alfresco.com/forum/installation-upgrades-configuration-integration/configuration/modifying-share-header-08252014

Los he leído, pero entiendo más o menos porque no soy un experto del ingles, he intentado modificar share-header.get.js y también he creado el fichero con xml "extension-modules.xml" donde C:\Alfresco\tomcat\webapps\share\WEB-INF\classes\alfresco\site-data\extensions, creo no falta nada más, pero me sale un error 500 general…, no sé por qué.., por eso tengo muchas dudas y creo que he desarrollado mal el código pero quiero enseñaros lo que he hecho:

share-header.get.js:

<import resource="classpath:/alfresco/site-webscripts/org/alfresco/share/imports/share-header.lib.js">

model.jsonModel = {
   rootNodeId: "share-header",
   services: getHeaderServices(),
   widgets: [
      {
         id: "SHARE_VERTICAL_LAYOUT",
         name: "alfresco/layout/VerticalWidgets",
         config:
         {
            widgets: getHeaderModel()
         }
      }
   ]
var widget = widgetUtils.findObject(model.jsonModel.widgets, "id", "HEADER_SHARED_FILES");
if(widget !== undefined && widget !== null)
{
   widget.name = null; // CreateWebScriptsWidgetsDirective checks name and only creates WidgetData if name is a string
}

var widget, widgetsToRemove = [ "HEADER_SHARED_FILES", "HEADER_MY_FILES", "HEADER_TASKS", "HEADER_SEARCH" ], idx, max;
for (idx = 0, max = widgetsToRemove.length; idx < max; idx++)
{
   findAndRemoveIn(model.jsonModel.widgets, null, null, widgetsToRemove[idx]);
}
function findAndRemoveIn(obj, arrContext, arrIdx, id)
{
   var idx, max, key;
   if (obj !== undefined && obj !== null)
   {
      if (Object.prototype.toString().apply(obj) === "[object Object]")
      {
         if (obj.hasOwnProperty("id") && obj.id === id)
         {
            if (arrContext !== null && arrIdx !== null)
            {
               arrContext.splice(arrIdx, 1);
            }
            else
            {   
               logger.debug("Unexpected match outside of array structure: " + jsonUtils.toJSONString(obj));
            }
         }
         else
         {
            for (key in obj)
            {
               if (obj.hasOwnProperty(key))
               {
                  findAndRemoveIn(obj[key], null, null, id);
               }
            }
         }
      }
      else if (Object.prototype.toString().apply(obj) === "[object Array]")
      {
         for (idx = 0, max = obj.length; idx < max; idx++)
         {
            findAndRemoveIn(obj[idx], obj, idx, id);
         }
      }
   }
}
};

extension-modules.xml:

<?xml version="1.0"?>
<extension>
   <modules>
      <module>
         <id>Remove Share Headers</id>
         <version>1.0</version>
          <auto-deploy>true</auto-deploy>
          <customizations>
            <customization>
               <targetPackageRoot>org.alfresco.share.header</targetPackageRoot>
               <sourcePackageRoot>share-mod.remove-headers-link</sourcePackageRoot>
            </customization>
          </customizations>
      </module>
      </modules>
</extension>

Me sale el error 500:

The Web Script /share/service/share-header has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   08150001 Failed to execute script 'classpath*:alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js': 08150000 TypeError: Cannot find function apply. (file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js#1939)

Exception:   org.mozilla.javascript.EcmaError - TypeError: Cannot find function apply. (file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js#1939)

org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)
org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3356)
org.mozilla.javascript.ScriptRuntime.typeError1(ScriptRuntime.java:3368)
org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3428)
org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2052)
org.mozilla.javascript.gen.c4._c32(file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js:1939)
org.mozilla.javascript.gen.c4.call(file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js)
org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
org.mozilla.javascript.gen.c4._c0(file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js:1932)
org.mozilla.javascript.gen.c4.call(file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
org.mozilla.javascript.gen.c4.call(file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js)
org.mozilla.javascript.gen.c4.exec(file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js)
org.springframework.extensions.webscripts.processor.JSScriptProcessor.executeScriptImpl(JSScriptProcessor.java:318)
org.springframework.extensions.webscripts.processor.JSScriptProcessor.executeScript(JSScriptProcessor.java:192)
org.springframework.extensions.webscripts.AbstractWebScript.executeScript(AbstractWebScript.java:1305)
org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)
org.springframework.extensions.webscripts.PresentationContainer.executeScript(PresentationContainer.java:70)
org.springframework.extensions.webscripts.LocalWebScriptRuntimeContainer.executeScript(LocalWebScriptRuntimeContainer.java:236)
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)
org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
org.springframework.extensions.webscripts.WebScriptProcessor.executeBody(WebScriptProcessor.java:310)
org.springframework.extensions.surf.render.AbstractProcessor.execute(AbstractProcessor.java:57)
org.springframework.extensions.surf.render.RenderService.process(RenderService.java:599)
org.springframework.extensions.surf.render.RenderService.renderSubComponent(RenderService.java:505)
org.springframework.extensions.surf.render.RenderService.processComponent(RenderService.java:419)
org.springframework.extensions.surf.render.RenderService.renderComponent(RenderService.java:942)
org.springframework.extensions.surf.render.RenderService.renderRegionComponents(RenderService.java:900)
org.springframework.extensions.surf.render.bean.RegionRenderer.body(RegionRenderer.java:89)
org.springframework.extensions.surf.render.AbstractRenderer.render(AbstractRenderer.java:77)
org.springframework.extensions.surf.render.RenderService.renderRegion(RenderService.java:851)
org.springframework.extensions.directives.RegionDirectiveData.render(RegionDirectiveData.java:91)
org.springframework.extensions.surf.extensibility.impl.ExtensibilityModelImpl.merge(ExtensibilityModelImpl.java:408)
org.springframework.extensions.surf.extensibility.impl.AbstractExtensibilityDirective.merge(AbstractExtensibilityDirective.java:169)
org.springframework.extensions.surf.extensibility.impl.AbstractExtensibilityDirective.execute(AbstractExtensibilityDirective.java:137)
freemarker.core.Environment.visit(Environment.java:274)
freemarker.core.UnifiedCall.accept(UnifiedCall.java:126)
freemarker.core.Environment.visit(Environment.java:221)
freemarker.core.MixedContent.accept(MixedContent.java:92)
freemarker.core.Environment.visit(Environment.java:221)
freemarker.core.Environment$3.render(Environment.java:246)
org.springframework.extensions.surf.extensibility.impl.DefaultExtensibilityDirectiveData.render(DefaultExtensibilityDirectiveData.java:119)
org.springframework.extensions.surf.extensibility.impl.ExtensibilityModelImpl.merge(ExtensibilityModelImpl.java:408)
org.springframework.extensions.surf.extensibility.impl.AbstractExtensibilityDirective.merge(AbstractExtensibilityDirective.java:169)
org.springframework.extensions.surf.extensibility.impl.AbstractExtensibilityDirective.execute(AbstractExtensibilityDirective.java:137)
freemarker.core.Environment.visit(Environment.java:274)
freemarker.core.UnifiedCall.accept(UnifiedCall.java:126)
freemarker.core.Environment.visit(Environment.java:221)
freemarker.core.MixedContent.accept(MixedContent.java:92)
freemarker.core.Environment.visit(Environment.java:221)
freemarker.core.Environment.visit(Environment.java:406)
freemarker.core.BodyInstruction.accept(BodyInstruction.java:93)
freemarker.core.Environment.visit(Environment.java:221)
freemarker.core.MixedContent.accept(MixedContent.java:92)
freemarker.core.Environment.visit(Environment.java:221)
freemarker.core.Macro$Context.runMacro(Macro.java:172)
freemarker.core.Environment.visit(Environment.java:614)
freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
freemarker.core.Environment.visit(Environment.java:221)
freemarker.core.MixedContent.accept(MixedContent.java:92)
freemarker.core.Environment.visit(Environment.java:221)
freemarker.core.Environment.process(Environment.java:199)
org.springframework.extensions.webscripts.processor.FTLTemplateProcessor.process(FTLTemplateProcessor.java:171)
org.springframework.extensions.webscripts.WebTemplateProcessor.executeBody(WebTemplateProcessor.java:438)
org.springframework.extensions.surf.render.AbstractProcessor.execute(AbstractProcessor.java:57)
org.springframework.extensions.surf.render.RenderService.processTemplate(RenderService.java:721)
org.springframework.extensions.surf.render.bean.TemplateInstanceRenderer.body(TemplateInstanceRenderer.java:140)
org.springframework.extensions.surf.render.AbstractRenderer.render(AbstractRenderer.java:77)
org.springframework.extensions.surf.render.bean.PageRenderer.body(PageRenderer.java:85)
org.springframework.extensions.surf.render.AbstractRenderer.render(AbstractRenderer.java:77)
org.springframework.extensions.surf.render.RenderService.renderPage(RenderService.java:762)
org.springframework.extensions.surf.mvc.PageView.dispatchPage(PageView.java:411)
org.springframework.extensions.surf.mvc.PageView.renderView(PageView.java:306)
org.springframework.extensions.surf.mvc.AbstractWebFrameworkView.renderMergedOutputModel(AbstractWebFrameworkView.java:316)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.alfresco.web.site.servlet.MTAuthenticationFilter.doFilter(MTAuthenticationFilter.java:74)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.alfresco.web.site.servlet.SecurityHeadersFilter.doFilter(SecurityHeadersFilter.java:168)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.alfresco.web.site.servlet.CSRFFilter.doFilter(CSRFFilter.java:313)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.alfresco.web.site.servlet.SSOAuthenticationFilter.doFilter(SSOAuthenticationFilter.java:378)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

Exception:   org.springframework.extensions.webscripts.WebScriptException - 08150000 TypeError: Cannot find function apply. (file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js#1939)

org.springframework.extensions.webscripts.processor.JSScriptProcessor.executeScriptImpl(JSScriptProcessor.java:328)

Exception:   org.springframework.extensions.webscripts.WebScriptException - 08150001 Failed to execute script 'classpath*:alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js': 08150000 TypeError: Cannot find function apply. (file:/C:/Alfresco/tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/share/header/share-header.get.js#1939)

org.springframework.extensions.webscripts.processor.JSScriptProcessor.executeScript(JSScriptProcessor.java:200)

Server:   Spring WebScripts - v1.2.0 (Release 1331) schema 1.000
Time:   15-sep-2014 12:39:41

Diagnostics:   Inspect Web Script (org/alfresco/share/header/share-header.get)

He estado probando varias veces pero aún me sale ese error…, pienso que estos cogidos no están bien…, alguien me podría ayudar

Muchas gracias

Un saludo

Outcomes