remove cancel button on login window if anonymous access is disabled, see issue #396

This commit is contained in:
Sebastian Sdorra
2013-12-27 17:17:59 +01:00
parent cf05c144cb
commit dfaa96b8ca
3 changed files with 32 additions and 16 deletions

View File

@@ -39,10 +39,13 @@ import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import freemarker.template.Configuration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import sonia.scm.SCMContextProvider; import sonia.scm.SCMContextProvider;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.resources.ResourceManager; import sonia.scm.resources.ResourceManager;
import sonia.scm.resources.ResourceType; import sonia.scm.resources.ResourceType;
import sonia.scm.util.IOUtil; import sonia.scm.util.IOUtil;
@@ -97,17 +100,18 @@ public class TemplateServlet extends HttpServlet
* *
* *
* @param context * @param context
* @param templateHandler
* @param templateEngineFactory * @param templateEngineFactory
* @param configuration
* @param resourceManager * @param resourceManager
*/ */
@Inject @Inject
public TemplateServlet(SCMContextProvider context, public TemplateServlet(SCMContextProvider context,
TemplateEngineFactory templateEngineFactory, TemplateEngineFactory templateEngineFactory,
ResourceManager resourceManager) ResourceManager resourceManager, ScmConfiguration configuration)
{ {
this.templateEngineFactory = templateEngineFactory; this.templateEngineFactory = templateEngineFactory;
this.resourceManager = resourceManager; this.resourceManager = resourceManager;
this.configuration = configuration;
this.version = context.getVersion(); this.version = context.getVersion();
} }
@@ -131,6 +135,7 @@ public class TemplateServlet extends HttpServlet
String contextPath = request.getContextPath(); String contextPath = request.getContextPath();
params.put("contextPath", contextPath); params.put("contextPath", contextPath);
params.put("configuration", configuration);
params.put("version", version); params.put("version", version);
params.put("scripts", resourceManager.getResources(ResourceType.SCRIPT)); params.put("scripts", resourceManager.getResources(ResourceType.SCRIPT));
@@ -237,11 +242,14 @@ public class TemplateServlet extends HttpServlet
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */
private ResourceManager resourceManager; private final ScmConfiguration configuration;
/** Field description */ /** Field description */
private TemplateEngineFactory templateEngineFactory; private final ResourceManager resourceManager;
/** Field description */ /** Field description */
private String version; private final TemplateEngineFactory templateEngineFactory;
/** Field description */
private final String version;
} }

View File

@@ -48,6 +48,9 @@
locale: '{{locale}}', locale: '{{locale}}',
country: '{{country}}' country: '{{country}}'
}; };
var scmGlobalConfiguration = {
anonymousAccessEnabled: {{configuration.anonymousAccessEnabled}}
};
</script> </script>
<!--compress--> <!--compress-->

View File

@@ -44,6 +44,21 @@ Sonia.login.Form = Ext.extend(Ext.FormPanel,{
rememberMeText: 'Remember me', rememberMeText: 'Remember me',
initComponent: function(){ initComponent: function(){
var buttons = [];
if (scmGlobalConfiguration.anonymousAccessEnabled){
buttons.push({
text: this.cancelText,
scope: this,
handler: this.cancel
});
}
buttons.push({
id: 'loginButton',
text: this.loginText,
formBind: true,
scope: this,
handler: this.authenticate
});
var config = { var config = {
labelWidth: 120, labelWidth: 120,
@@ -85,17 +100,7 @@ Sonia.login.Form = Ext.extend(Ext.FormPanel,{
name: 'rememberMe', name: 'rememberMe',
inputValue: 'true' inputValue: 'true'
}], }],
buttons:[{ buttons: buttons
text: this.cancelText,
scope: this,
handler: this.cancel
},{
id: 'loginButton',
text: this.loginText,
formBind: true,
scope: this,
handler: this.authenticate
}]
}; };
this.addEvents('cancel', 'failure'); this.addEvents('cancel', 'failure');