| | |
| | |
|
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.LinkedHashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.markup.html.form.PasswordTextField;
|
| | |
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.TeamModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.PageRegistration;
|
| | | import com.gitblit.wicket.PageRegistration.DropDownMenuItem;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.NavigationPanel;
|
| | |
|
| | |
| | |
|
| | | @Override
|
| | | protected void setupPage(String repositoryName, String pageName) {
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, false);
|
| | | boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true);
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, true);
|
| | | |
| | | if (authenticateAdmin) { |
| | | showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
|
| | | // authentication requires state and session
|
| | | setStatelessHint(false);
|
| | | } else {
|
| | | showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateViewPages, false)) {
|
| | | showAdmin = allowAdmin;
|
| | | if (authenticateView) {
|
| | | // authentication requires state and session
|
| | | setStatelessHint(false);
|
| | | } else {
|
| | |
| | | // navigation links
|
| | | List<PageRegistration> pages = new ArrayList<PageRegistration>();
|
| | | pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class));
|
| | | pages.add(new PageRegistration("gb.activity", ActivityPage.class));
|
| | | if (showAdmin) {
|
| | | pages.add(new PageRegistration("gb.users", UsersPage.class));
|
| | | }
|
| | | if (showAdmin || showRegistrations) {
|
| | | pages.add(new PageRegistration("gb.federation", FederationPage.class));
|
| | | } |
| | | }
|
| | |
|
| | | if (!authenticateView || (authenticateView && GitBlitWebSession.get().isLoggedIn())) {
|
| | | addDropDownMenus(pages);
|
| | | }
|
| | |
|
| | | NavigationPanel navPanel = new NavigationPanel("navPanel", getClass(), pages);
|
| | | add(navPanel);
|
| | |
|
| | |
| | | WicketUtils.setInputPlaceholder(pwField, getString("gb.password"));
|
| | | loginForm.add(pwField);
|
| | | add(loginForm);
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateViewPages, true)
|
| | | || GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | |
| | | if (authenticateView || authenticateAdmin) {
|
| | | loginForm.setVisible(!GitBlitWebSession.get().isLoggedIn());
|
| | | } else {
|
| | | loginForm.setVisible(false);
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | protected void addDropDownMenus(List<PageRegistration> pages) {
|
| | |
|
| | | }
|
| | |
|
| | | protected List<DropDownMenuItem> getFilterMenuItems() {
|
| | | final UserModel user = GitBlitWebSession.get().getUser();
|
| | | Set<DropDownMenuItem> filters = new LinkedHashSet<DropDownMenuItem>();
|
| | |
|
| | | // accessible repositories by federation set
|
| | | for (RepositoryModel repository : GitBlit.self().getRepositoryModels(user)) {
|
| | | for (String set : repository.federationSets) {
|
| | | filters.add(new DropDownMenuItem(set, "set", set));
|
| | | }
|
| | | }
|
| | | if (filters.size() > 0) {
|
| | | // divider
|
| | | filters.add(new DropDownMenuItem());
|
| | | }
|
| | |
|
| | | // user's team memberships
|
| | | if (user != null && user.teams.size() > 0) {
|
| | | for (TeamModel team : user.teams) {
|
| | | filters.add(new DropDownMenuItem(team.name, "team", team.name));
|
| | | }
|
| | | // divider
|
| | | filters.add(new DropDownMenuItem());
|
| | | }
|
| | |
|
| | | // custom filters
|
| | | String customFilters = GitBlit.getString(Keys.web.customFilters, null);
|
| | | if (!StringUtils.isEmpty(customFilters)) {
|
| | | List<String> expressions = StringUtils.getStringsFromValue(customFilters, "!!!");
|
| | | for (String expression : expressions) {
|
| | | filters.add(new DropDownMenuItem(null, "x", expression));
|
| | | }
|
| | | }
|
| | |
|
| | | if (filters.size() > 0) {
|
| | | // if we have any filters, add the divider
|
| | | filters.add(new DropDownMenuItem());
|
| | | // add All Repositories
|
| | | filters.add(new DropDownMenuItem("All Repositories", null, null));
|
| | | }
|
| | |
|
| | | return new ArrayList<DropDownMenuItem>(filters);
|
| | | }
|
| | |
|
| | | protected List<RepositoryModel> getRepositories(PageParameters params) {
|
| | | final UserModel user = GitBlitWebSession.get().getUser();
|
| | | if (params == null) {
|
| | | return GitBlit.self().getRepositoryModels(user);
|
| | | }
|
| | |
|
| | | String repositoryName = WicketUtils.getRepositoryName(params);
|
| | | String set = WicketUtils.getSet(params);
|
| | | String regex = WicketUtils.getRegEx(params);
|
| | | String team = WicketUtils.getTeam(params);
|
| | |
|
| | | List<RepositoryModel> models = null;
|
| | |
|
| | | if (!StringUtils.isEmpty(repositoryName)) {
|
| | | // try named repository
|
| | | models = new ArrayList<RepositoryModel>();
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
| | | if (user.canAccessRepository(model)) {
|
| | | models.add(model);
|
| | | }
|
| | | }
|
| | |
|
| | | // get all user accessible repositories
|
| | | if (models == null) {
|
| | | models = GitBlit.self().getRepositoryModels(user);
|
| | | }
|
| | |
|
| | | if (!StringUtils.isEmpty(regex)) {
|
| | | // filter the repositories by the regex
|
| | | List<RepositoryModel> accessible = GitBlit.self().getRepositoryModels(user);
|
| | | List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();
|
| | | Pattern pattern = Pattern.compile(regex);
|
| | | for (RepositoryModel aModel : accessible) {
|
| | | if (pattern.matcher(aModel.name).find()) {
|
| | | matchingModels.add(aModel);
|
| | | }
|
| | | }
|
| | | models = matchingModels;
|
| | | } else if (!StringUtils.isEmpty(set)) {
|
| | | // filter the repositories by the specified sets
|
| | | List<String> sets = StringUtils.getStringsFromValue(set, ",");
|
| | | List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();
|
| | | for (RepositoryModel model : models) {
|
| | | for (String curr : sets) {
|
| | | if (model.federationSets.contains(curr)) {
|
| | | matchingModels.add(model);
|
| | | }
|
| | | }
|
| | | }
|
| | | models = matchingModels;
|
| | | } else if (!StringUtils.isEmpty(team)) {
|
| | | // filter the repositories by the specified teams
|
| | | List<String> teams = StringUtils.getStringsFromValue(team, ",");
|
| | |
|
| | | // need TeamModels first
|
| | | List<TeamModel> teamModels = new ArrayList<TeamModel>();
|
| | | for (String name : teams) {
|
| | | TeamModel model = GitBlit.self().getTeamModel(name);
|
| | | if (model != null) {
|
| | | teamModels.add(model);
|
| | | }
|
| | | }
|
| | |
|
| | | // brute-force our way through finding the matching models
|
| | | List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();
|
| | | for (RepositoryModel repositoryModel : models) {
|
| | | for (TeamModel teamModel : teamModels) {
|
| | | if (teamModel.hasRepository(repositoryModel.name)) {
|
| | | matchingModels.add(repositoryModel);
|
| | | }
|
| | | }
|
| | | }
|
| | | models = matchingModels;
|
| | | }
|
| | | return models;
|
| | | }
|
| | | }
|