From 9a7bf46675d60ed001a3f2cdb115e893301d7d02 Mon Sep 17 00:00:00 2001
From: diminator
Date: Mon, 13 Jul 2015 23:57:16 +0200
Subject: [PATCH] acl WIP
---
.../accordion_list_item.js | 4 +-
.../accordion_list_item_edition_widget.js | 37 +++++++++----------
js/components/ascribe_buttons/acl_button.js | 2 +-
.../ascribe_buttons/create_editions_button.js | 2 +-
.../ascribe_buttons/delete_button.js | 2 +-
js/components/ascribe_detail/piece.js | 3 +-
.../ascribe_forms/form_delete_edition.js | 5 ++-
.../form_remove_editions_from_collection.js | 9 ++++-
js/constants/api_urls.js | 1 +
js/utils/acl_utils.js | 4 +-
10 files changed, 38 insertions(+), 31 deletions(-)
diff --git a/js/components/ascribe_accordion_list/accordion_list_item.js b/js/components/ascribe_accordion_list/accordion_list_item.js
index 150d6934..6651f264 100644
--- a/js/components/ascribe_accordion_list/accordion_list_item.js
+++ b/js/components/ascribe_accordion_list/accordion_list_item.js
@@ -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
}
};
}
diff --git a/js/components/ascribe_accordion_list/accordion_list_item_edition_widget.js b/js/components/ascribe_accordion_list/accordion_list_item_edition_widget.js
index 02328382..abd6e7b2 100644
--- a/js/components/ascribe_accordion_list/accordion_list_item_edition_widget.js
+++ b/js/components/ascribe_accordion_list/accordion_list_item_edition_widget.js
@@ -73,31 +73,28 @@ let AccordionListItemEditionWidget = React.createClass({
let numEditions = piece.num_editions;
if(numEditions <= 0) {
- return (
-
- );
- } else if(numEditions === 1) {
- let editionMapping = piece && piece.first_edition ? piece.first_edition.edition_number + '/' + piece.num_editions : '';
+ if (piece.acl.acl_editions){
+ return (
+
+ );
+ }
+ else {
+ return null;
+ }
+
+ } else {
+ let editionMapping = piece && piece.first_edition ? piece.first_edition.num_editions_available + '/' + piece.num_editions : '';
return (
- );
- }
- else {
- return (
-
);
}
diff --git a/js/components/ascribe_buttons/acl_button.js b/js/components/ascribe_buttons/acl_button.js
index 5f1cb3a0..e3998759 100644
--- a/js/components/ascribe_buttons/acl_button.js
+++ b/js/components/ascribe_buttons/acl_button.js
@@ -88,7 +88,7 @@ let AclButton = React.createClass({
GlobalNotificationActions.appendGlobalNotification(notification);
},
- // plz move to share form
+ // plz move to share form
getTitlesString(){
if (this.isPiece()){
return '\"' + this.props.pieceOrEditions.title + '\"';
diff --git a/js/components/ascribe_buttons/create_editions_button.js b/js/components/ascribe_buttons/create_editions_button.js
index ec341473..beeb1e97 100644
--- a/js/components/ascribe_buttons/create_editions_button.js
+++ b/js/components/ascribe_buttons/create_editions_button.js
@@ -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;
}
diff --git a/js/components/ascribe_buttons/delete_button.js b/js/components/ascribe_buttons/delete_button.js
index df7c536a..614401f0 100644
--- a/js/components/ascribe_buttons/delete_button.js
+++ b/js/components/ascribe_buttons/delete_button.js
@@ -45,7 +45,7 @@ let DeleteButton = React.createClass({
content = ;
btnDelete = ;
}
- else if (availableAcls.acl_unshare){
+ else if (availableAcls.acl_unshare || (this.props.editions.constructor !== Array && this.props.editions.acl.acl_unshare)){
content = ;
btnDelete = ;
}
diff --git a/js/components/ascribe_detail/piece.js b/js/components/ascribe_detail/piece.js
index 9a410d29..4b1430f2 100644
--- a/js/components/ascribe_detail/piece.js
+++ b/js/components/ascribe_detail/piece.js
@@ -113,7 +113,8 @@ let Piece = React.createClass({
+ editions={this.props.piece}
+ handleSuccess={this.props.loadPiece}>
{getLangText('Are you sure you would like to permanently delete this edition')}?
{getLangText('This is an irrevocable action%s', '.')}
-
-
+
+
);
diff --git a/js/components/ascribe_forms/form_remove_editions_from_collection.js b/js/components/ascribe_forms/form_remove_editions_from_collection.js
index 0ba13975..fd3af834 100644
--- a/js/components/ascribe_forms/form_remove_editions_from_collection.js
+++ b/js/components/ascribe_forms/form_remove_editions_from_collection.js
@@ -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';
diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js
index 6d3ce7c8..f262b9fc 100644
--- a/js/constants/api_urls.js
+++ b/js/constants/api_urls.js
@@ -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/',
diff --git a/js/utils/acl_utils.js b/js/utils/acl_utils.js
index 4f287c96..69ade6d3 100644
--- a/js/utils/acl_utils.js
+++ b/js/utils/acl_utils.js
@@ -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