| | |
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.TreeSet;
|
| | | import java.util.concurrent.atomic.AtomicInteger;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | import org.apache.wicket.MarkupContainer;
|
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.behavior.HeaderContributor;
|
| | | import org.apache.wicket.markup.html.IHeaderContributor;
|
| | | import org.apache.wicket.markup.html.IHeaderResponse;
|
| | | import org.apache.wicket.markup.html.basic.Label;
|
| | | import org.apache.wicket.markup.html.form.PasswordTextField;
|
| | | import org.apache.wicket.markup.html.form.TextField;
|
| | |
| | | import org.apache.wicket.protocol.http.WebResponse;
|
| | |
|
| | | 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.ModelUtils;
|
| | | 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.PageRegistration.DropDownToggleItem;
|
| | | import com.gitblit.wicket.SessionlessForm;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.GravatarImage;
|
| | |
| | | /**
|
| | | * Root page is a topbar, navigable page like Repositories, Users, or
|
| | | * Federation.
|
| | | * |
| | | *
|
| | | * @author James Moger
|
| | | * |
| | | *
|
| | | */
|
| | | public abstract class RootPage extends BasePage {
|
| | |
|
| | |
| | |
|
| | | @Override
|
| | | protected void setupPage(String repositoryName, String pageName) {
|
| | | boolean authenticateView = GitBlit.getBoolean(Keys.web.authenticateViewPages, false);
|
| | | boolean authenticateAdmin = GitBlit.getBoolean(Keys.web.authenticateAdminPages, true);
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, true);
|
| | |
|
| | | // CSS header overrides
|
| | | add(new HeaderContributor(new IHeaderContributor() {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | @Override
|
| | | public void renderHead(IHeaderResponse response) {
|
| | | StringBuilder buffer = new StringBuilder();
|
| | | buffer.append("<style type=\"text/css\">\n");
|
| | | buffer.append(".navbar-inner {\n");
|
| | | final String headerBackground = app().settings().getString(Keys.web.headerBackgroundColor, null);
|
| | | if (!StringUtils.isEmpty(headerBackground)) {
|
| | | buffer.append(MessageFormat.format("background-color: {0};\n", headerBackground));
|
| | | }
|
| | | final String headerBorder = app().settings().getString(Keys.web.headerBorderColor, null);
|
| | | if (!StringUtils.isEmpty(headerBorder)) {
|
| | | buffer.append(MessageFormat.format("border-bottom: 1px solid {0} !important;\n", headerBorder));
|
| | | }
|
| | | buffer.append("}\n");
|
| | | final String headerBorderFocus = app().settings().getString(Keys.web.headerBorderFocusColor, null);
|
| | | if (!StringUtils.isEmpty(headerBorderFocus)) {
|
| | | buffer.append(".navbar ul li:focus, .navbar .active {\n");
|
| | | buffer.append(MessageFormat.format("border-bottom: 4px solid {0};\n", headerBorderFocus));
|
| | | buffer.append("}\n");
|
| | | }
|
| | | final String headerForeground = app().settings().getString(Keys.web.headerForegroundColor, null);
|
| | | if (!StringUtils.isEmpty(headerForeground)) {
|
| | | buffer.append(".navbar ul.nav li a {\n");
|
| | | buffer.append(MessageFormat.format("color: {0};\n", headerForeground));
|
| | | buffer.append("}\n");
|
| | | buffer.append(".navbar ul.nav .active a {\n");
|
| | | buffer.append(MessageFormat.format("color: {0};\n", headerForeground));
|
| | | buffer.append("}\n");
|
| | | }
|
| | | final String headerHover = app().settings().getString(Keys.web.headerHoverColor, null);
|
| | | if (!StringUtils.isEmpty(headerHover)) {
|
| | | buffer.append(".navbar ul.nav li a:hover {\n");
|
| | | buffer.append(MessageFormat.format("color: {0} !important;\n", headerHover));
|
| | | buffer.append("}\n");
|
| | | }
|
| | | buffer.append("</style>\n");
|
| | | response.renderString(buffer.toString());
|
| | | }
|
| | | }));
|
| | |
|
| | | boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, false);
|
| | | boolean authenticateAdmin = app().settings().getBoolean(Keys.web.authenticateAdminPages, true);
|
| | | boolean allowAdmin = app().settings().getBoolean(Keys.web.allowAdministration, true);
|
| | | boolean allowLucene = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);
|
| | | boolean isLoggedIn = GitBlitWebSession.get().isLoggedIn();
|
| | |
|
| | | if (authenticateAdmin) {
|
| | | showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
|
| | |
| | | setStatelessHint(true);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | if (authenticateView || authenticateAdmin) {
|
| | | if (GitBlitWebSession.get().isLoggedIn()) {
|
| | | if (isLoggedIn) {
|
| | | UserMenu userFragment = new UserMenu("userPanel", "userMenuFragment", RootPage.this);
|
| | | add(userFragment);
|
| | | } else {
|
| | |
| | | } else {
|
| | | add(new Label("userPanel").setVisible(false));
|
| | | }
|
| | | |
| | | boolean showRegistrations = GitBlit.canFederate()
|
| | | && GitBlit.getBoolean(Keys.web.showFederationRegistrations, false);
|
| | |
|
| | | boolean showRegistrations = app().federation().canFederate()
|
| | | && app().settings().getBoolean(Keys.web.showFederationRegistrations, false);
|
| | |
|
| | | // navigation links
|
| | | List<PageRegistration> pages = new ArrayList<PageRegistration>();
|
| | | if (!authenticateView || (authenticateView && GitBlitWebSession.get().isLoggedIn())) {
|
| | | // pages.add(new PageRegistration("gb.home", HomePage.class,
|
| | | // getRootPageParameters()));
|
| | | if (!authenticateView || (authenticateView && isLoggedIn)) {
|
| | | pages.add(new PageRegistration(isLoggedIn ? "gb.myDashboard" : "gb.dashboard", MyDashboardPage.class,
|
| | | getRootPageParameters()));
|
| | | pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class,
|
| | | getRootPageParameters()));
|
| | | pages.add(new PageRegistration("gb.activity", ActivityPage.class, getRootPageParameters()));
|
| | | if (GitBlit.getBoolean(Keys.web.allowLuceneIndexing, true)) {
|
| | | if(isLoggedIn)
|
| | | {
|
| | | pages.add(new PageRegistration("gb.mytickets", MyTicketsPage.class, getRootPageParameters()));
|
| | | }
|
| | | if (allowLucene) {
|
| | | pages.add(new PageRegistration("gb.search", LuceneSearchPage.class));
|
| | | }
|
| | | if (showAdmin) {
|
| | |
| | | pages.add(new PageRegistration("gb.federation", FederationPage.class));
|
| | | }
|
| | |
|
| | | if (!authenticateView || (authenticateView && GitBlitWebSession.get().isLoggedIn())) {
|
| | | if (!authenticateView || (authenticateView && isLoggedIn)) {
|
| | | addDropDownMenus(pages);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | NavigationPanel navPanel = new NavigationPanel("navPanel", getRootNavPageClass(), pages);
|
| | | add(navPanel);
|
| | |
|
| | |
| | | if (!StringUtils.isEmpty(cachedMessage)) {
|
| | | error(cachedMessage);
|
| | | } else if (showAdmin) {
|
| | | int pendingProposals = GitBlit.self().getPendingFederationProposals().size();
|
| | | int pendingProposals = app().federation().getPendingFederationProposals().size();
|
| | | if (pendingProposals == 1) {
|
| | | info(getString("gb.OneProposalToReview"));
|
| | | } else if (pendingProposals > 1) {
|
| | |
| | |
|
| | | super.setupPage(repositoryName, pageName);
|
| | | }
|
| | | |
| | |
|
| | | protected Class<? extends BasePage> getRootNavPageClass() {
|
| | | return getClass();
|
| | | }
|
| | |
| | |
|
| | | // remove days back parameter if it is the default value
|
| | | if (params.containsKey("db")
|
| | | && params.getInt("db") == GitBlit.getInteger(Keys.web.activityDuration, 14)) {
|
| | | && params.getInt("db") == app().settings().getInteger(Keys.web.activityDuration, 7)) {
|
| | | params.remove("db");
|
| | | }
|
| | | return params;
|
| | | } |
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
| | | session.setUser(user);
|
| | |
|
| | | // Set Cookie
|
| | | if (GitBlit.getBoolean(Keys.web.allowCookieAuthentication, false)) {
|
| | | if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) {
|
| | | WebResponse response = (WebResponse) getRequestCycle().getResponse();
|
| | | GitBlit.self().setCookie(response, user);
|
| | | app().authentication().setCookie(response.getHttpServletResponse(), user);
|
| | | }
|
| | |
|
| | | if (!session.continueRequest()) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | protected List<RepositoryModel> getRepositoryModels() {
|
| | | if (repositoryModels.isEmpty()) {
|
| | | final UserModel user = GitBlitWebSession.get().getUser();
|
| | | List<RepositoryModel> repositories = GitBlit.self().getRepositoryModels(user);
|
| | | List<RepositoryModel> repositories = app().repositories().getRepositoryModels(user);
|
| | | repositoryModels.addAll(repositories);
|
| | | Collections.sort(repositoryModels);
|
| | | }
|
| | |
| | | List<String> sets = new ArrayList<String>(setMap.keySet());
|
| | | Collections.sort(sets);
|
| | | for (String set : sets) {
|
| | | filters.add(new DropDownMenuItem(MessageFormat.format("{0} ({1})", set,
|
| | | filters.add(new DropDownToggleItem(MessageFormat.format("{0} ({1})", set,
|
| | | setMap.get(set).get()), "set", set, params));
|
| | | }
|
| | | // divider
|
| | |
| | | List<TeamModel> teams = new ArrayList<TeamModel>(user.teams);
|
| | | Collections.sort(teams);
|
| | | for (TeamModel team : teams) {
|
| | | filters.add(new DropDownMenuItem(MessageFormat.format("{0} ({1})", team.name,
|
| | | filters.add(new DropDownToggleItem(MessageFormat.format("{0} ({1})", team.name,
|
| | | team.repositories.size()), "team", team.name, params));
|
| | | }
|
| | | // divider
|
| | |
| | | }
|
| | |
|
| | | // custom filters
|
| | | String customFilters = GitBlit.getString(Keys.web.customFilters, null);
|
| | | String customFilters = app().settings().getString(Keys.web.customFilters, null);
|
| | | if (!StringUtils.isEmpty(customFilters)) {
|
| | | boolean addedExpression = false;
|
| | | List<String> expressions = StringUtils.getStringsFromValue(customFilters, "!!!");
|
| | | for (String expression : expressions) {
|
| | | if (!StringUtils.isEmpty(expression)) {
|
| | | addedExpression = true;
|
| | | filters.add(new DropDownMenuItem(null, "x", expression, params));
|
| | | filters.add(new DropDownToggleItem(null, "x", expression, params));
|
| | | }
|
| | | }
|
| | | // if we added any custom expressions, add a divider
|
| | |
| | |
|
| | | protected List<DropDownMenuItem> getTimeFilterItems(PageParameters params) {
|
| | | // days back choices - additive parameters
|
| | | int daysBack = GitBlit.getInteger(Keys.web.activityDuration, 14);
|
| | | int daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
|
| | | int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
|
| | | if (daysBack < 1) {
|
| | | daysBack = 14;
|
| | | daysBack = 7;
|
| | | }
|
| | | if (daysBack > maxDaysBack) {
|
| | | daysBack = maxDaysBack;
|
| | | }
|
| | | PageParameters clonedParams;
|
| | | if (params == null) {
|
| | | clonedParams = new PageParameters();
|
| | | } else {
|
| | | clonedParams = new PageParameters(params);
|
| | | }
|
| | |
|
| | | if (!clonedParams.containsKey("db")) {
|
| | | clonedParams.put("db", daysBack);
|
| | | }
|
| | |
|
| | | List<DropDownMenuItem> items = new ArrayList<DropDownMenuItem>();
|
| | | Set<Integer> choicesSet = new HashSet<Integer>(Arrays.asList(daysBack, 14, 28, 60, 90, 180));
|
| | | Set<Integer> choicesSet = new TreeSet<Integer>(app().settings().getIntegers(Keys.web.activityDurationChoices));
|
| | | if (choicesSet.isEmpty()) {
|
| | | choicesSet.addAll(Arrays.asList(1, 3, 7, 14, 21, 28));
|
| | | }
|
| | | List<Integer> choices = new ArrayList<Integer>(choicesSet);
|
| | | Collections.sort(choices);
|
| | | String lastDaysPattern = getString("gb.lastNDays");
|
| | | for (Integer db : choices) {
|
| | | String txt = MessageFormat.format(lastDaysPattern, db);
|
| | | items.add(new DropDownMenuItem(txt, "db", db.toString(), params));
|
| | | if (db == 1) {
|
| | | items.add(new DropDownMenuItem(getString("gb.time.today"), "db", db.toString(), clonedParams));
|
| | | } else {
|
| | | String txt = MessageFormat.format(lastDaysPattern, db);
|
| | | items.add(new DropDownMenuItem(txt, "db", db.toString(), clonedParams));
|
| | | }
|
| | | }
|
| | | items.add(new DropDownMenuItem());
|
| | | return items;
|
| | |
| | | String userName = WicketUtils.getUsername(params);
|
| | | if (StringUtils.isEmpty(projectName)) {
|
| | | if (!StringUtils.isEmpty(userName)) {
|
| | | projectName = "~" + userName;
|
| | | projectName = ModelUtils.getPersonalPath(userName);
|
| | | }
|
| | | }
|
| | | String repositoryName = WicketUtils.getRepositoryName(params);
|
| | |
| | | String regex = WicketUtils.getRegEx(params);
|
| | | String team = WicketUtils.getTeam(params);
|
| | | int daysBack = params.getInt("db", 0);
|
| | | int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
|
| | |
|
| | | List<RepositoryModel> availableModels = getRepositoryModels();
|
| | | Set<RepositoryModel> models = new HashSet<RepositoryModel>();
|
| | |
| | |
|
| | | if (!StringUtils.isEmpty(projectName)) {
|
| | | // try named project
|
| | | hasParameter = true; |
| | | if (projectName.equalsIgnoreCase(GitBlit.getString(Keys.web.repositoryRootGroupName, "main"))) {
|
| | | hasParameter = true;
|
| | | if (projectName.equalsIgnoreCase(app().settings().getString(Keys.web.repositoryRootGroupName, "main"))) {
|
| | | // root project/group
|
| | | for (RepositoryModel model : availableModels) {
|
| | | if (model.name.indexOf('/') == -1) {
|
| | |
| | | // need TeamModels first
|
| | | List<TeamModel> teamModels = new ArrayList<TeamModel>();
|
| | | for (String name : teams) {
|
| | | TeamModel teamModel = GitBlit.self().getTeamModel(name);
|
| | | TeamModel teamModel = app().users().getTeamModel(name);
|
| | | if (teamModel != null) {
|
| | | teamModels.add(teamModel);
|
| | | }
|
| | |
| | |
|
| | | // time-filter the list
|
| | | if (daysBack > 0) {
|
| | | if (maxDaysBack > 0 && daysBack > maxDaysBack) {
|
| | | daysBack = maxDaysBack;
|
| | | }
|
| | | Calendar cal = Calendar.getInstance();
|
| | | cal.set(Calendar.HOUR_OF_DAY, 0);
|
| | | cal.set(Calendar.MINUTE, 0);
|
| | |
| | | }
|
| | | models = timeFiltered;
|
| | | }
|
| | | |
| | |
|
| | | List<RepositoryModel> list = new ArrayList<RepositoryModel>(models);
|
| | | Collections.sort(list);
|
| | | return list;
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Inline login form. |
| | | * Inline login form.
|
| | | */
|
| | | private class LoginForm extends Fragment {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
| | | String username = RootPage.this.username.getObject();
|
| | | char[] password = RootPage.this.password.getObject().toCharArray();
|
| | |
|
| | | UserModel user = GitBlit.self().authenticate(username, password);
|
| | | UserModel user = app().authentication().authenticate(username, password);
|
| | | if (user == null) {
|
| | | error(getString("gb.invalidUsernameOrPassword"));
|
| | | } else if (user.username.equals(Constants.FEDERATION_USER)) {
|
| | |
| | | add(loginForm);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Menu for the authenticated user.
|
| | | */
|
| | | static class UserMenu extends Fragment {
|
| | | class UserMenu extends Fragment {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | |
| | |
|
| | | GitBlitWebSession session = GitBlitWebSession.get();
|
| | | UserModel user = session.getUser();
|
| | | boolean editCredentials = GitBlit.self().supportsCredentialChanges(user);
|
| | | boolean editCredentials = app().authentication().supportsCredentialChanges(user);
|
| | | boolean standardLogin = session.authenticationType.isStandard();
|
| | |
|
| | | if (GitBlit.getBoolean(Keys.web.allowGravatar, true)) {
|
| | | add(new GravatarImage("username", user.getDisplayName(),
|
| | | user.emailAddress, "navbarGravatar", 20, false, false));
|
| | | if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {
|
| | | add(new GravatarImage("username", user, "navbarGravatar", 20, false));
|
| | | } else {
|
| | | add(new Label("username", user.getDisplayName()));
|
| | | }
|
| | |
|
| | | add(new Label("displayName", user.getDisplayName()));
|
| | | |
| | | add(new BookmarkablePageLink<Void>("myProfile", |
| | |
|
| | | add(new BookmarkablePageLink<Void>("newRepository",
|
| | | EditRepositoryPage.class).setVisible(user.canAdmin() || user.canCreate()));
|
| | |
|
| | | add(new BookmarkablePageLink<Void>("myProfile",
|
| | | UserPage.class, WicketUtils.newUsernameParameter(user.username)));
|
| | |
|
| | | add(new BookmarkablePageLink<Void>("changePassword", |
| | | add(new BookmarkablePageLink<Void>("changePassword",
|
| | | ChangePasswordPage.class).setVisible(editCredentials));
|
| | | |
| | |
|
| | | add(new BookmarkablePageLink<Void>("logout",
|
| | | LogoutPage.class).setVisible(standardLogin));
|
| | | }
|