mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
acl WIP
This commit is contained in:
parent
a985fb855e
commit
9a7bf46675
@ -83,7 +83,7 @@ let AccordionListItem = React.createClass({
|
||||
render() {
|
||||
let linkData;
|
||||
|
||||
if(this.props.content.num_editions < 1) {
|
||||
if(this.props.content.num_editions < 1 || !this.props.content.first_edition) {
|
||||
linkData = {
|
||||
to: 'piece',
|
||||
params: {
|
||||
@ -94,7 +94,7 @@ let AccordionListItem = React.createClass({
|
||||
linkData = {
|
||||
to: 'edition',
|
||||
params: {
|
||||
editionId: this.props.content.first_edition ? this.props.content.first_edition.bitcoin_id : 0
|
||||
editionId: this.props.content.first_edition.bitcoin_id
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -73,31 +73,28 @@ let AccordionListItemEditionWidget = React.createClass({
|
||||
let numEditions = piece.num_editions;
|
||||
|
||||
if(numEditions <= 0) {
|
||||
return (
|
||||
<CreateEditionsButton
|
||||
label={getLangText('Create editions')}
|
||||
className="btn-xs pull-right"
|
||||
piece={piece}
|
||||
toggleCreateEditionsDialog={this.props.toggleCreateEditionsDialog}
|
||||
onPollingSuccess={this.props.onPollingSuccess}/>
|
||||
);
|
||||
} else if(numEditions === 1) {
|
||||
let editionMapping = piece && piece.first_edition ? piece.first_edition.edition_number + '/' + piece.num_editions : '';
|
||||
if (piece.acl.acl_editions){
|
||||
return (
|
||||
<CreateEditionsButton
|
||||
label={getLangText('Create editions')}
|
||||
className="btn-xs pull-right"
|
||||
piece={piece}
|
||||
toggleCreateEditionsDialog={this.props.toggleCreateEditionsDialog}
|
||||
onPollingSuccess={this.props.onPollingSuccess}/>
|
||||
);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
let editionMapping = piece && piece.first_edition ? piece.first_edition.num_editions_available + '/' + piece.num_editions : '';
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={this.toggleTable}
|
||||
className={classNames('btn', 'btn-default', 'btn-xs', 'ascribe-accordion-list-item-edition-widget', this.props.className)}>
|
||||
{editionMapping + ' ' + getLangText('Edition')} {this.getGlyphicon()}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
else {
|
||||
return (
|
||||
<button
|
||||
onClick={this.toggleTable}
|
||||
className={classNames('btn', 'btn-default', 'btn-xs', 'ascribe-accordion-list-item-edition-widget', this.props.className)}>
|
||||
{numEditions + ' ' + getLangText('Editions')} {this.getGlyphicon()}
|
||||
{editionMapping + ' ' + getLangText('Editions')} {this.getGlyphicon()}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ let CreateEditionsButton = React.createClass({
|
||||
|
||||
let availableAcls = getAvailableAcls(piece);
|
||||
|
||||
if (availableAcls.editions || piece.num_editions > 0){
|
||||
if (!piece.acl.acl_editions || piece.num_editions > 0){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ let DeleteButton = React.createClass({
|
||||
content = <EditionDeleteForm editions={ this.props.editions }/>;
|
||||
btnDelete = <Button bsStyle="danger" className="btn-delete" bsSize="small">{getLangText('DELETE')}</Button>;
|
||||
}
|
||||
else if (availableAcls.acl_unshare){
|
||||
else if (availableAcls.acl_unshare || (this.props.editions.constructor !== Array && this.props.editions.acl.acl_unshare)){
|
||||
content = <EditionRemoveFromCollectionForm editions={ this.props.editions }/>;
|
||||
btnDelete = <Button bsStyle="danger" className="btn-delete" bsSize="small">{getLangText('REMOVE FROM COLLECTION')}</Button>;
|
||||
}
|
||||
|
@ -113,7 +113,8 @@ let Piece = React.createClass({
|
||||
<AclButtonList
|
||||
className="text-center ascribe-button-list"
|
||||
availableAcls={this.props.piece.acl}
|
||||
editions={this.props.piece}>
|
||||
editions={this.props.piece}
|
||||
handleSuccess={this.props.loadPiece}>
|
||||
<CreateEditionsButton
|
||||
label={getLangText('CREATE EDITIONS')}
|
||||
className="btn-sm"
|
||||
|
@ -24,8 +24,9 @@ let EditionDeleteForm = React.createClass({
|
||||
<p>{getLangText('Are you sure you would like to permanently delete this edition')}?</p>
|
||||
<p>{getLangText('This is an irrevocable action%s', '.')}</p>
|
||||
<div className="modal-footer">
|
||||
<button type="submit" className="btn btn-ascribe-inv" onClick={this.submit}>{getLangText('YES, DELETE')}</button>
|
||||
<button className="btn btn-ascribe" onClick={this.props.onRequestHide}>{getLangText('CLOSE')}</button>
|
||||
<button type="submit" className="btn btn-danger btn-delete btn-sm ascribe-margin-1px" onClick={this.submit}>{getLangText('YES, DELETE')}</button>
|
||||
<button className="btn btn-default btn-sm ascribe-margin-1px" style={{marginLeft: '0'}}
|
||||
onClick={this.props.onRequestHide}>{getLangText('CLOSE')}</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { getLangText } from '../../utils/lang_utils.js'
|
||||
import { getLangText } from '../../utils/lang_utils.js';
|
||||
import requests from '../../utils/requests';
|
||||
import apiUrls from '../../constants/api_urls';
|
||||
import FormMixin from '../../mixins/form_mixin';
|
||||
@ -12,7 +12,12 @@ let EditionRemoveFromCollectionForm = React.createClass({
|
||||
mixins: [FormMixin],
|
||||
|
||||
url() {
|
||||
return requests.prepareUrl(apiUrls.edition_remove_from_collection, {edition_id: this.getBitcoinIds().join()});
|
||||
if (this.props.editions.constructor === Array) {
|
||||
return requests.prepareUrl(apiUrls.edition_remove_from_collection, {edition_id: this.getBitcoinIds().join()});
|
||||
}
|
||||
else {
|
||||
return requests.prepareUrl(apiUrls.piece_remove_from_collection, {piece_id: this.editions.piece_id});
|
||||
}
|
||||
},
|
||||
httpVerb(){
|
||||
return 'delete';
|
||||
|
@ -37,6 +37,7 @@ let apiUrls = {
|
||||
'piece_first_edition_id': AppConstants.apiEndpoint + 'pieces/${piece_id}/edition_index/',
|
||||
'pieces_list': AppConstants.apiEndpoint + 'pieces/',
|
||||
'pieces_list_request_actions': AppConstants.apiEndpoint + 'pieces/request_actions/',
|
||||
'piece_remove_from_collection': AppConstants.apiEndpoint + 'ownership/shares/pieces/${piece_id}/',
|
||||
'user': AppConstants.apiEndpoint + 'users/',
|
||||
'users_login': AppConstants.apiEndpoint + 'users/login/',
|
||||
'users_logout': AppConstants.apiEndpoint + 'users/logout/',
|
||||
|
@ -8,7 +8,9 @@ function intersectAcls(a, b) {
|
||||
|
||||
export function getAvailableAcls(editions) {
|
||||
let availableAcls = [];
|
||||
|
||||
if (editions.constructor !== Array){
|
||||
return [];
|
||||
}
|
||||
// if you copy a javascript array of objects using slice, then
|
||||
// the object reference is still there.
|
||||
// Therefore we need to do this ugly copying
|
||||
|
Loading…
Reference in New Issue
Block a user