public EditRepositoryPage() { // create constructor super(); isCreate = true; RepositoryModel model = new RepositoryModel(); String restriction = GitBlit.getString(Keys.git.defaultAccessRestriction, null); model.accessRestriction = AccessRestrictionType.fromName(restriction); String authorization = GitBlit.getString(Keys.git.defaultAuthorizationControl, null); model.authorizationControl = AuthorizationControl.fromName(authorization); GitBlitWebSession session = GitBlitWebSession.get(); UserModel user = session.getUser(); if (user != null && user.canCreate() && !user.canAdmin()) { // personal create permissions, inject personal repository path model.name = user.getPersonalPath() + "/"; model.projectPath = user.getPersonalPath(); model.addOwner(user.username); // personal repositories are private by default model.accessRestriction = AccessRestrictionType.VIEW; model.authorizationControl = AuthorizationControl.NAMED; } setupPage(model); setStatelessHint(false); setOutputMarkupId(true); }
private boolean validateFields() { String rname = nameField.getText(); if (StringUtils.isEmpty(rname)) { error("Please enter a repository name!"); return false; } // automatically convert backslashes to forward slashes rname = rname.replace('\\', '/'); // Automatically replace // with / rname = rname.replace("//", "/"); // prohibit folder paths if (rname.startsWith("/")) { error("Leading root folder references (/) are prohibited."); return false; } if (rname.startsWith("../")) { error("Relative folder references (../) are prohibited."); return false; } if (rname.contains("/../")) { error("Relative folder references (../) are prohibited."); return false; } // confirm valid characters in repository name Character c = StringUtils.findInvalidCharacter(rname); if (c != null) { error(MessageFormat.format("Illegal character ''{0}'' in repository name!", c)); return false; } // verify repository name uniqueness on create if (isCreate) { // force repo names to lowercase // this means that repository name checking for rpc creation // is case-insensitive, regardless of the Gitblit server's // filesystem if (repositoryNames.contains(rname.toLowerCase())) { error( MessageFormat.format( "Can not create repository ''{0}'' because it already exists.", rname)); return false; } } else { // check rename collision if (!repositoryName.equalsIgnoreCase(rname)) { if (repositoryNames.contains(rname.toLowerCase())) { error( MessageFormat.format( "Failed to rename ''{0}'' because ''{1}'' already exists.", repositoryName, rname)); return false; } } } if (accessRestriction.getSelectedItem() == null) { error("Please select access restriction!"); return false; } if (federationStrategy.getSelectedItem() == null) { error("Please select federation strategy!"); return false; } repository.name = rname; repository.description = descriptionField.getText(); repository.owner = ownerField.getSelectedItem() == null ? null : ownerField.getSelectedItem().toString(); repository.HEAD = headRefField.getSelectedItem() == null ? null : headRefField.getSelectedItem().toString(); repository.useTickets = useTickets.isSelected(); repository.useDocs = useDocs.isSelected(); repository.showRemoteBranches = showRemoteBranches.isSelected(); repository.showReadme = showReadme.isSelected(); repository.skipSizeCalculation = skipSizeCalculation.isSelected(); repository.skipSummaryMetrics = skipSummaryMetrics.isSelected(); repository.isFrozen = isFrozen.isSelected(); String ml = mailingListsField.getText(); if (!StringUtils.isEmpty(ml)) { Set<String> list = new HashSet<String>(); for (String address : ml.split("(,|\\s)")) { if (StringUtils.isEmpty(address)) { continue; } list.add(address.toLowerCase()); } repository.mailingLists = new ArrayList<String>(list); } repository.accessRestriction = (AccessRestrictionType) accessRestriction.getSelectedItem(); repository.federationStrategy = (FederationStrategy) federationStrategy.getSelectedItem(); if (repository.federationStrategy.exceeds(FederationStrategy.EXCLUDE)) { repository.federationSets = setsPalette.getSelections(); } repository.indexedBranches = indexedBranchesPalette.getSelections(); repository.preReceiveScripts = preReceivePalette.getSelections(); repository.postReceiveScripts = postReceivePalette.getSelections(); // Custom Fields repository.customFields = new LinkedHashMap<String, String>(); if (customTextfields != null) { for (JTextField field : customTextfields) { String key = field.getName(); String value = field.getText(); repository.customFields.put(key, value); } } return true; }