Search in sources :

Example 1 with AuthorizationControl

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);
}
Also used : ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) PropertyModel(org.apache.wicket.model.PropertyModel) Fragment(org.apache.wicket.markup.html.panel.Fragment) ListView(org.apache.wicket.markup.html.list.ListView) Model(org.apache.wicket.model.Model) RepositoryModel(com.gitblit.models.RepositoryModel) PropertyModel(org.apache.wicket.model.PropertyModel) AccessRestrictionType(com.gitblit.Constants.AccessRestrictionType) AuthorizationControl(com.gitblit.Constants.AuthorizationControl) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 2 with AuthorizationControl

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);
}
Also used : RepositoryNamePanel(com.gitblit.wicket.panels.RepositoryNamePanel) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) GitBlitException(com.gitblit.GitBlitException) SimpleAttributeModifier(org.apache.wicket.behavior.SimpleAttributeModifier) RepositoryModel(com.gitblit.models.RepositoryModel) BooleanChoiceOption(com.gitblit.wicket.panels.BooleanChoiceOption) Button(org.apache.wicket.markup.html.form.Button) AccessRestrictionType(com.gitblit.Constants.AccessRestrictionType) AuthorizationControl(com.gitblit.Constants.AuthorizationControl) File(java.io.File) AccessPolicyPanel(com.gitblit.wicket.panels.AccessPolicyPanel) BooleanOption(com.gitblit.wicket.panels.BooleanOption)

Aggregations

AccessRestrictionType (com.gitblit.Constants.AccessRestrictionType)2 AuthorizationControl (com.gitblit.Constants.AuthorizationControl)2 RepositoryModel (com.gitblit.models.RepositoryModel)2 ArrayList (java.util.ArrayList)2 GitBlitException (com.gitblit.GitBlitException)1 AccessPolicyPanel (com.gitblit.wicket.panels.AccessPolicyPanel)1 BooleanChoiceOption (com.gitblit.wicket.panels.BooleanChoiceOption)1 BooleanOption (com.gitblit.wicket.panels.BooleanOption)1 RepositoryNamePanel (com.gitblit.wicket.panels.RepositoryNamePanel)1 File (java.io.File)1 SimpleAttributeModifier (org.apache.wicket.behavior.SimpleAttributeModifier)1 Label (org.apache.wicket.markup.html.basic.Label)1 Button (org.apache.wicket.markup.html.form.Button)1 Form (org.apache.wicket.markup.html.form.Form)1 ListItem (org.apache.wicket.markup.html.list.ListItem)1 ListView (org.apache.wicket.markup.html.list.ListView)1 Fragment (org.apache.wicket.markup.html.panel.Fragment)1 CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)1 Model (org.apache.wicket.model.Model)1 PropertyModel (org.apache.wicket.model.PropertyModel)1