mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
fix authentication selector for correct browser rendering if anonymous access is active
This commit is contained in:
@@ -1,25 +1,13 @@
|
||||
// @flow
|
||||
import React, { Component } from "react";
|
||||
import React, {Component} from "react";
|
||||
import Main from "./Main";
|
||||
import { connect } from "react-redux";
|
||||
import { translate } from "react-i18next";
|
||||
import { withRouter } from "react-router-dom";
|
||||
import {
|
||||
fetchMe,
|
||||
isAuthenticated,
|
||||
getMe,
|
||||
isFetchMePending,
|
||||
getFetchMeFailure
|
||||
} from "../modules/auth";
|
||||
import {connect} from "react-redux";
|
||||
import {translate} from "react-i18next";
|
||||
import {withRouter} from "react-router-dom";
|
||||
import {fetchMe, getFetchMeFailure, getMe, isAuthenticated, isFetchMePending} from "../modules/auth";
|
||||
|
||||
import {
|
||||
PrimaryNavigation,
|
||||
Loading,
|
||||
ErrorPage,
|
||||
Footer,
|
||||
Header
|
||||
} from "@scm-manager/ui-components";
|
||||
import type { Links, Me } from "@scm-manager/ui-types";
|
||||
import {ErrorPage, Footer, Header, Loading, PrimaryNavigation} from "@scm-manager/ui-components";
|
||||
import type {Links, Me} from "@scm-manager/ui-types";
|
||||
import {
|
||||
getFetchIndexResourcesFailure,
|
||||
getLinks,
|
||||
@@ -50,23 +38,10 @@ class App extends Component<Props> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
me,
|
||||
loading,
|
||||
error,
|
||||
authenticated,
|
||||
links,
|
||||
t
|
||||
} = this.props;
|
||||
const {me, loading, error, authenticated, links, t} = this.props;
|
||||
|
||||
let content;
|
||||
const navigation = authenticated ? (
|
||||
<PrimaryNavigation
|
||||
links={links}
|
||||
/>
|
||||
) : (
|
||||
""
|
||||
);
|
||||
const navigation = authenticated ? <PrimaryNavigation links={links}/> : "";
|
||||
|
||||
if (loading) {
|
||||
content = <Loading />;
|
||||
@@ -85,7 +60,7 @@ class App extends Component<Props> {
|
||||
<div className="App">
|
||||
<Header>{navigation}</Header>
|
||||
{content}
|
||||
<Footer me={me} />
|
||||
{authenticated && <Footer me={me}/>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
import React from "react";
|
||||
import { Redirect, withRouter } from "react-router-dom";
|
||||
import {
|
||||
login,
|
||||
getLoginFailure,
|
||||
isAuthenticated,
|
||||
isLoginPending,
|
||||
getLoginFailure
|
||||
login
|
||||
} from "../modules/auth";
|
||||
import { connect } from "react-redux";
|
||||
import { getLoginLink, getLoginInfoLink } from "../modules/indexResource";
|
||||
import { getLoginInfoLink, getLoginLink } from "../modules/indexResource";
|
||||
import LoginInfo from "../components/LoginInfo";
|
||||
import classNames from "classnames";
|
||||
import injectSheet from "react-jss";
|
||||
@@ -37,7 +37,6 @@ type Props = {
|
||||
};
|
||||
|
||||
class Login extends React.Component<Props> {
|
||||
|
||||
handleLogin = (username: string, password: string): void => {
|
||||
const { link, login } = this.props;
|
||||
login(link, username, password);
|
||||
@@ -45,7 +44,7 @@ class Login extends React.Component<Props> {
|
||||
|
||||
renderRedirect = () => {
|
||||
const { from } = this.props.location.state || { from: { pathname: "/" } };
|
||||
return <Redirect to={from}/>;
|
||||
return <Redirect to={from} />;
|
||||
};
|
||||
|
||||
render() {
|
||||
@@ -56,7 +55,7 @@ class Login extends React.Component<Props> {
|
||||
}
|
||||
|
||||
return (
|
||||
<section className={classNames("hero", classes.section )}>
|
||||
<section className={classNames("hero", classes.section)}>
|
||||
<div className="hero-body">
|
||||
<div className="container">
|
||||
<div className="columns is-centered">
|
||||
@@ -65,7 +64,7 @@ class Login extends React.Component<Props> {
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
// @flow
|
||||
import type { Me } from "@scm-manager/ui-types";
|
||||
import type {Me} from "@scm-manager/ui-types";
|
||||
import * as types from "./types";
|
||||
|
||||
import { apiClient, UnauthorizedError } from "@scm-manager/ui-components";
|
||||
import { isPending } from "./pending";
|
||||
import { getFailure } from "./failure";
|
||||
import {apiClient, UnauthorizedError} from "@scm-manager/ui-components";
|
||||
import {isPending} from "./pending";
|
||||
import {getFailure} from "./failure";
|
||||
import {
|
||||
callFetchIndexResources,
|
||||
fetchIndexResources,
|
||||
fetchIndexResourcesPending,
|
||||
fetchIndexResourcesSuccess
|
||||
fetchIndexResourcesSuccess,
|
||||
getLoginLink
|
||||
} from "./indexResource";
|
||||
|
||||
// Action
|
||||
@@ -44,13 +45,11 @@ export default function reducer(
|
||||
case FETCH_ME_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
me: action.payload,
|
||||
authenticated: true
|
||||
me: action.payload
|
||||
};
|
||||
case FETCH_ME_UNAUTHORIZED:
|
||||
return {
|
||||
me: {},
|
||||
authenticated: false
|
||||
me: {}
|
||||
};
|
||||
case LOGOUT_SUCCESS:
|
||||
return initialState;
|
||||
@@ -240,7 +239,7 @@ const stateAuth = (state: Object): Object => {
|
||||
};
|
||||
|
||||
export const isAuthenticated = (state: Object) => {
|
||||
if (stateAuth(state).authenticated) {
|
||||
if (state.auth.me && !getLoginLink(state)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -6,12 +6,12 @@ import de.otto.edison.hal.Embedded;
|
||||
import de.otto.edison.hal.Link;
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.config.ConfigurationPermissions;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.group.GroupPermissions;
|
||||
import sonia.scm.plugin.PluginPermissions;
|
||||
import sonia.scm.repository.RepositoryRolePermissions;
|
||||
import sonia.scm.security.PermissionPermissions;
|
||||
import sonia.scm.user.UserPermissions;
|
||||
|
||||
@@ -50,6 +50,11 @@ public class IndexDtoGenerator extends HalAppenderMapper {
|
||||
link("me", resourceLinks.me().self()),
|
||||
link("logout", resourceLinks.authentication().logout())
|
||||
);
|
||||
|
||||
if (SecurityUtils.getSubject().getPrincipal().equals(SCMContext.USER_ANONYMOUS)) {
|
||||
builder.single(link("login", resourceLinks.authentication().jsonLogin()));
|
||||
}
|
||||
|
||||
if (PluginPermissions.read().isPermitted()) {
|
||||
builder.single(link("installedPlugins", resourceLinks.installedPluginCollection().self()));
|
||||
builder.single(link("availablePlugins", resourceLinks.availablePluginCollection().self()));
|
||||
|
||||
Reference in New Issue
Block a user