Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow anonymous user navigation in the project's collaboration tab #987

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/api-client/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function addIssueMethods(client) {
};


client.getContributions = (projectId, issueIid) => {
client.getContributions = async (projectId, issueIid) => {
let headers = client.getBasicHeaders();
headers.append("Content-Type", "application/json");

Expand All @@ -66,6 +66,16 @@ function addIssueMethods(client) {
};


client.getContributionsAnonymous = async (projectSlug, issueIid) => {
let headers = client.getBasicHeaders();

return client.clientFetch(`${client.baseUrl}/direct/${projectSlug}/-/issues/${issueIid}/discussions`, {
method: "GET",
headers: headers
});
};


client.postContribution = (projectId, issueIid, contribution) => {
let headers = client.getBasicHeaders();
headers.append("Content-Type", "application/json");
Expand Down
34 changes: 21 additions & 13 deletions src/collaboration/issue/Issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class View extends Component {
this.state = { contributions: [] };
}

componentDidMount() {
async componentDidMount() {
this._mounted = true;
this.retrieveContributions();
}
Expand Down Expand Up @@ -209,18 +209,26 @@ class View extends Component {
});
}

retrieveContributions() {
this.props.client.getContributions(this.props.projectId, this.props.issueIid)
.then(resp => {
if (!this._mounted) return;
this.setState((prevState, props) => {
return { contributions: resp.data };
});
}).catch(error => {
this.setState((prevState, props) => {
return { contributions: [] };
});
});
async retrieveContributions() {
const { client, projectId, issueIid, user, projectPathWithNamespace } = this.props;
let contributions;
try {
// use different query for anonymous and logged user
if (user.logged) {
const resp = await client.getContributions(projectId, issueIid);
contributions = resp.data;
}
else {
const resp = await client.getContributionsAnonymous(projectPathWithNamespace, issueIid);
contributions = resp.data.map(item => item.notes[0]);
}
if (!this._mounted)
return;
this.setState({ contributions });
}
catch (e) {
this.setState({ contributions: [] });
}
}


Expand Down
5 changes: 4 additions & 1 deletion src/contribution/Contribution.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class ContributionBody extends React.Component {
constructor(props) {
super(props);
this._mounted = false;
const blocks = matchRefs(this.props.contribution.body);
const body = this.props.contribution.body ?
this.props.contribution.body :
this.props.contribution.note;
const blocks = matchRefs(body);
this.state = { blocks };
}

Expand Down