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