use of com.gitblit.Constants.AuthorizationControl in project gitblit by gitblit.
the class AccessPolicyPanel method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
AccessPolicy anonymousPolicy = new AccessPolicy(getString("gb.anonymousPolicy"), getString("gb.anonymousPolicyDescription"), "blank.png", AuthorizationControl.AUTHENTICATED, AccessRestrictionType.NONE);
AccessPolicy authenticatedPushPolicy = new AccessPolicy(getString("gb.authenticatedPushPolicy"), getString("gb.authenticatedPushPolicyDescription"), "lock_go_16x16.png", AuthorizationControl.AUTHENTICATED, AccessRestrictionType.PUSH);
AccessPolicy namedPushPolicy = new AccessPolicy(getString("gb.namedPushPolicy"), getString("gb.namedPushPolicyDescription"), "lock_go_16x16.png", AuthorizationControl.NAMED, AccessRestrictionType.PUSH);
AccessPolicy clonePolicy = new AccessPolicy(getString("gb.clonePolicy"), getString("gb.clonePolicyDescription"), "lock_pull_16x16.png", AuthorizationControl.NAMED, AccessRestrictionType.CLONE);
AccessPolicy viewPolicy = new AccessPolicy(getString("gb.viewPolicy"), getString("gb.viewPolicyDescription"), "shield_16x16.png", AuthorizationControl.NAMED, AccessRestrictionType.VIEW);
List<AccessPolicy> policies = new ArrayList<AccessPolicy>();
if (app().settings().getBoolean(Keys.git.allowAnonymousPushes, false)) {
policies.add(anonymousPolicy);
}
policies.add(authenticatedPushPolicy);
policies.add(namedPushPolicy);
policies.add(clonePolicy);
policies.add(viewPolicy);
AccessRestrictionType defaultRestriction = repository.accessRestriction;
if (defaultRestriction == null) {
defaultRestriction = AccessRestrictionType.fromName(app().settings().getString(Keys.git.defaultAccessRestriction, AccessRestrictionType.PUSH.name()));
}
AuthorizationControl defaultControl = repository.authorizationControl;
if (defaultControl == null) {
defaultControl = AuthorizationControl.fromName(app().settings().getString(Keys.git.defaultAuthorizationControl, AuthorizationControl.NAMED.name()));
}
AccessPolicy defaultPolicy = namedPushPolicy;
for (AccessPolicy policy : policies) {
if (policy.type == defaultRestriction && policy.control == defaultControl) {
defaultPolicy = policy;
}
}
policiesGroup = new RadioGroup<>("policiesGroup", new Model<AccessPolicy>(defaultPolicy));
ListView<AccessPolicy> policiesList = new ListView<AccessPolicy>("policies", policies) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<AccessPolicy> item) {
AccessPolicy p = item.getModelObject();
item.add(new Radio<AccessPolicy>("radio", item.getModel()));
item.add(WicketUtils.newImage("image", p.image));
item.add(new Label("name", p.name));
item.add(new Label("description", p.description));
}
};
policiesGroup.add(policiesList);
if (callback != null) {
policiesGroup.add(callback);
policiesGroup.setOutputMarkupId(true);
}
add(policiesGroup);
if (app().settings().getBoolean(Keys.web.allowForking, true)) {
Fragment fragment = new Fragment("allowForks", "allowForksFragment", this);
fragment.add(new BooleanOption("allowForks", getString("gb.allowForks"), getString("gb.allowForksDescription"), new PropertyModel<Boolean>(repository, "allowForks")));
add(fragment);
} else {
add(new Label("allowForks").setVisible(false));
}
setOutputMarkupId(true);
}
use of com.gitblit.Constants.AuthorizationControl in project gitblit by gitblit.
the class NewRepositoryPage method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
CompoundPropertyModel<RepositoryModel> rModel = new CompoundPropertyModel<>(repositoryModel);
Form<RepositoryModel> form = new Form<RepositoryModel>("editForm", rModel) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit() {
try {
if (!namePanel.updateModel(repositoryModel)) {
return;
}
accessPolicyPanel.updateModel(repositoryModel);
repositoryModel.owners = new ArrayList<String>();
repositoryModel.owners.add(GitBlitWebSession.get().getUsername());
// setup branch defaults
boolean useGitFlow = addGitflowModel.getObject();
repositoryModel.HEAD = Constants.R_MASTER;
repositoryModel.mergeTo = Constants.MASTER;
if (useGitFlow) {
// tickets normally merge to develop unless they are hotfixes
repositoryModel.mergeTo = Constants.DEVELOP;
}
repositoryModel.allowForks = app().settings().getBoolean(Keys.web.allowForking, true);
// optionally generate an initial commit
boolean addReadme = addReadmeModel.getObject();
String gitignore = null;
boolean addGitignore = addGitignoreModel.getObject();
if (addGitignore) {
gitignore = gitignoreModel.getObject();
if (StringUtils.isEmpty(gitignore)) {
throw new GitBlitException(getString("gb.pleaseSelectGitIgnore"));
}
}
// init the repository
app().gitblit().updateRepositoryModel(repositoryModel.name, repositoryModel, true);
// optionally create an initial commit
initialCommit(repositoryModel, addReadme, gitignore, useGitFlow);
} catch (GitBlitException e) {
error(e.getMessage());
return;
}
setRedirect(true);
setResponsePage(SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryModel.name));
}
};
// do not let the browser pre-populate these fields
form.add(new SimpleAttributeModifier("autocomplete", "off"));
namePanel = new RepositoryNamePanel("namePanel", repositoryModel);
form.add(namePanel);
// prepare the default access controls
AccessRestrictionType defaultRestriction = AccessRestrictionType.fromName(app().settings().getString(Keys.git.defaultAccessRestriction, AccessRestrictionType.PUSH.name()));
if (AccessRestrictionType.NONE == defaultRestriction) {
defaultRestriction = AccessRestrictionType.PUSH;
}
AuthorizationControl defaultControl = AuthorizationControl.fromName(app().settings().getString(Keys.git.defaultAuthorizationControl, AuthorizationControl.NAMED.name()));
if (AuthorizationControl.AUTHENTICATED == defaultControl) {
defaultRestriction = AccessRestrictionType.PUSH;
}
repositoryModel.authorizationControl = defaultControl;
repositoryModel.accessRestriction = defaultRestriction;
accessPolicyPanel = new AccessPolicyPanel("accessPolicyPanel", repositoryModel);
form.add(accessPolicyPanel);
//
// initial commit options
//
// add README
addReadmeModel = Model.of(false);
form.add(new BooleanOption("addReadme", getString("gb.initWithReadme"), getString("gb.initWithReadmeDescription"), addReadmeModel));
// add .gitignore
File gitignoreDir = app().runtime().getFileOrFolder(Keys.git.gitignoreFolder, "${baseFolder}/gitignore");
File[] files = gitignoreDir.listFiles();
if (files == null) {
files = new File[0];
}
List<String> gitignores = new ArrayList<String>();
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".gitignore")) {
gitignores.add(StringUtils.stripFileExtension(file.getName()));
}
}
Collections.sort(gitignores);
gitignoreModel = Model.of("");
addGitignoreModel = Model.of(false);
form.add(new BooleanChoiceOption<String>("addGitIgnore", getString("gb.initWithGitignore"), getString("gb.initWithGitignoreDescription"), addGitignoreModel, gitignoreModel, gitignores).setVisible(gitignores.size() > 0));
// TODO consider gitflow at creation (ticket-55)
addGitflowModel = Model.of(false);
form.add(new BooleanOption("addGitFlow", "Include a .gitflow file", "This will generate a config file which guides Git clients in setting up Gitflow branches.", addGitflowModel).setVisible(false));
form.add(new Button("create"));
add(form);
}
Aggregations