Bug 9780

Summary: Restrict the right to suppress a record used in some order
Product: Koha Reporter: mathieu saby <mathsabypro>
Component: CatalogingAssignee: mathieu saby <mathsabypro>
Status: CLOSED FIXED QA Contact: Paul Poulain <paul.poulain>
Severity: major    
Priority: P4 CC: christophe.croullebois, gitbot, gmcharlt, jonathan.druart+koha, julian.maurice, katrin.fischer, m.de.rooy, paul.poulain, tredok.pierre
Version: master   
Hardware: All   
OS: All   
See Also: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=5781
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on:    
Bug Blocks: 11303, 11829, 23166    
Attachments: [PATCH] Bug 9780: Alert librarians if a record is used by orders and prevent its suppression
[PATCH] Bug 9780: Alert librarians if a record is used by orders and prevent its suppression
[PATCH 2] Bug 9780: Don't show comma at the end of the line
[PATCH 2] Bug 9780: Don't show comma at the end of the line
Bug 9780: Show if a record is used by orders and prevent its suppression
[SIGNED-OFF] Bug 9780: Show if a record is used by orders and prevent its suppression
[PATCH][Revised] Bug 9780: Show if a record is used by orders and prevent its suppression
[PATCH 2/2] Bug 9780: Add unit test and a new condition in GetOrdersByBiblionumber
[PATCH 2/2] Bug 9780: Add unit test and a new condition in GetOrdersByBiblionumber
[PATCH] Bug 9780 : Restric the right to suppress a record used in some order
Bug 9780 : Restric the right to suppress a record used in some order
[PATCH 2] Bug 9780 QA Followup : suppress line feeds in javascript

Description mathieu saby 2013-03-10 18:09:49 UTC
There should be an alert preventing librarian to suppress a record if it is used in some orders.

M. Saby
Comment 1 mathieu saby 2013-03-11 00:12:49 UTC Comment hidden (obsolete)
Comment 2 mathieu saby 2013-03-11 00:14:07 UTC Comment hidden (obsolete)
Comment 3 mathieu saby 2013-03-15 11:59:55 UTC Comment hidden (obsolete)
Comment 4 mathieu saby 2013-03-15 13:46:48 UTC Comment hidden (obsolete)
Comment 5 Christophe Croullebois 2013-03-15 15:06:45 UTC
Hello Mathieu,
sry, but :
1° : in your patch you have whitespace errors, not a problem to test but later for QA... I paste the git am message :
=================================
Applying: Bug 9780: Alert librarians if a record is used by orders and prevent its suppression
/home/christophe/workspace/versions/community/.git/rebase-apply/patch:49: trailing whitespace.
        WHERE   aqorders.biblionumber=?            
/home/christophe/workspace/versions/community/.git/rebase-apply/patch:89: trailing whitespace.
	}	
/home/christophe/workspace/versions/community/.git/rebase-apply/patch:91: trailing whitespace.
    else {	
/home/christophe/workspace/versions/community/.git/rebase-apply/patch:95: trailing whitespace.
	    }	    
/home/christophe/workspace/versions/community/.git/rebase-apply/patch:135: trailing whitespace.
	     [% END %] 	 
warning: squelched 14 whitespace errors
warning: 19 lines add whitespace errors.

===================================
2° : in your patch 2 
===================================
Applying: Bug 9780: Don't show comma at the end of the line
/home/christophe/workspace/versions/community/.git/rebase-apply/patch:115: trailing whitespace.
                                                [%- UNLESS loop.last %],[% END %]                                
error: patch failed: koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt:136
error: koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt: patch does not apply
Patch failed at 0001 Bug 9780: Don't show comma at the end of the line
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".

===================================
As I was able to apply the patch1, I am going to test the patch without the follow up, please rebase for the followup
thx
Comment 6 mathieu saby 2013-03-15 16:29:07 UTC
I forgot to mention : 
you must test it with AND without XSLT activated, to be sure it is OK

At first, I wanted to add a new tab like "Holdings" and "More details", for "Orders". Maybe if would be better than displaying order information at record level ?
But in the template code I saw 3 conditional blocks for displaying Lists, Tags, and Holds, so I decided to add my code just before.

M. Saby
Comment 7 mathieu saby 2013-03-15 17:07:17 UTC Comment hidden (obsolete)
Comment 8 Julian Maurice 2013-03-18 11:21:34 UTC Comment hidden (obsolete)
Comment 9 Paul Poulain 2013-03-18 16:06:46 UTC
Trying to test to QA this patch. I need more info on this :
2) in basket A, create 2 orders with a single record (with no items attached)

does it means this patch does not work/is useless when AcqCreateItem syspref=ordering ?

2nd point : there are some tabs, instead of 4 spaces. (the number in () is the line number where there's a TAB)

 * catalogue/detail.pl                                                      FAIL
	forbidden patterns          FAIL
		The patch introduces a forbidden pattern: tabulation character (420)
		The patch introduces a forbidden pattern: tabulation character (419)
		The patch introduces a forbidden pattern: tabulation character (418)
		The patch introduces a forbidden pattern: tabulation character (417)
		The patch introduces a forbidden pattern: tabulation character (412)
		The patch introduces a forbidden pattern: tabulation character (414)
		The patch introduces a forbidden pattern: tabulation character (413)
		The patch introduces a forbidden pattern: tabulation character (411)
 * koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc                 FAIL
	forbidden patterns          FAIL
		The patch introduces a forbidden pattern: tabulation character (34)
		The patch introduces a forbidden pattern: tabulation character (51)
		The patch introduces a forbidden pattern: tabulation character (50)
		The patch introduces a forbidden pattern: tabulation character (46)
		The patch introduces a forbidden pattern: tabulation character (44)
		The patch introduces a forbidden pattern: tabulation character (49)
		The patch introduces a forbidden pattern: tabulation character (41)
		The patch introduces a forbidden pattern: tabulation character (47)
		The patch introduces a forbidden pattern: tabulation character (48)
		The patch introduces a forbidden pattern: tabulation character (35)
Comment 10 mathieu saby 2013-03-18 16:15:26 UTC
Paul,
1. I will correct tabulations tomorrow
2. For AcqCreateItem syspref=ordering, well, I need to look into this issue... The patch was made mainly for Rennes 2, and we are creating items at reception. 

M. Saby
Comment 11 mathieu saby 2013-03-18 19:09:20 UTC
This patch has nothing to do with AcqCreateItem syspref.
The message displayed at the end of the record will be the same whether items are created or not when ordering.
If items are creating when receiving or cataloguing, the message will be very useful. If items are creating when ordering, it will be less useful, but I believe it will not be considered as annoying.

All what I meant by "with no item attached", was that in order to test the new control on deleting record, you need to have a record without items, because the first test koha makes is checking if the record have some items attached.
So if items are creating when ordering, you need to suppress them in order to test the patch

I change the test plan to make it clearer :

4) check that record in catalog (detail.pl page) : you should see a line saying it is used 3 times, in baskets A and B
5) if some items are attached to that record, suppress all items

17) check the record in the catalog : you should see information, but without any link to basket A
18) if some items are attached to that record, suppress all items

M. Saby
Comment 12 mathieu saby 2013-03-18 19:10:33 UTC Comment hidden (obsolete)
Comment 13 Paul Poulain 2013-03-20 11:21:45 UTC
QA comment:
 * passes koha-qa.pl, great
 * works as advertised, great

However, some QA comments:
* lines like
+my $count_orders_using_biblio = scalar @orders_using_biblio ;
+$template->param (countorders => $count_orders_using_biblio);
can be removed = the .size pragma in template toolkit will achieve the same result.

$template->parameters(orders_using_biblio => @orders_using_biblio)
then in the template, just use [% orders_using_biblio.size %]

* lines related to affecting T::T can be merged. Instead of
+$template->param (basketsorders => \@baskets_orders);
+$template->param (basketsdeletedorders => \@baskets_deletedorders);
write
+$template->param (basketsorders => \@baskets_orders,
+                  basketsdeletedorders => \@baskets_deletedorders);

* instead of
Number of order(s) using this title: X active order(s) in basket(s) #NN, #PP
write
Order(s) using this title: X (basket #NN, ##PP)

* the reason why I failed QA this patch : it adds a sub in C4/Acquisitions.pm, but no unit test is provided for it.
Comment 14 mathieu saby 2013-03-22 11:23:15 UTC Comment hidden (obsolete)
Comment 15 mathieu saby 2013-04-06 09:56:18 UTC
I have just realized the aim of this patch is partially the same as BZ 7294.
Please read the comment I left under 7294

M. Saby
Comment 16 Marcel de Rooy 2013-04-11 11:29:43 UTC
Applying: Bug 9780: Add unit test and a new condition in GetOrdersByBiblionumber
/usr/share/koha/testclone/.git/rebase-apply/patch:56: trailing whitespace.
   ok( scalar (@listorders) >0,'GetOrdersByBiblionumber : result contains at least one element' );
fatal: sha1 information is lacking or useless (C4/Acquisition.pm).
Repository lacks necessary blobs to fall back on 3-way merge.
Comment 17 mathieu saby 2013-04-12 13:38:39 UTC Comment hidden (obsolete)
Comment 18 mathieu saby 2013-04-14 11:52:17 UTC
patch under BZ 6777 is also about the same problem...

BZ 9780 is doing 2 things :
1) prevent librarians to suppress a record if used by orders
2) display acq information under the record in details.pl

It is the only bug fixing 1).
But there are 2 other bugs about 2) : BZ 6777 and BZ 7294, with different logic.

I propose to rewrite BZ9780, focusing on 1) only, as it was the main issue I wanted to fix.

For 2), we can make an other patch to display Acq information, either in tabs, or under the record.

I will work on rewriting BZ9780 next week.

M. Saby
Comment 19 Jonathan Druart 2013-04-24 09:47:37 UTC
(In reply to comment #18)
> I propose to rewrite BZ9780, focusing on 1) only, as it was the main issue I
> wanted to fix.

Yes Mathieu, I think it is the easier way. I will try to manage with all others bugs relating to the acq details in biblio pages.
Comment 20 mathieu saby 2013-04-24 15:23:41 UTC
In fact, the more I look into this problem, the more I think my solution is not realy good : there can be some situation where suppressing a record linked to orders should be allowed, for example if the library withdraw items some months after having bought them...

So maybe a more fundamental change is needed, so that information in basket will not be deleted if we delete the record : 
- either in the basket, use info stored deletedbiblioitems and deletedbiblios as well as biblios and biblioitems
- or store bibliographic information (title, author...) in aqorders table (bug 9548, N. Engard liked the idea)

The 2d option is more radical, but should allow librarians to have always exactly the same information when they print a basketgroup in pdf. 
At present, we need to store the pdf somewhere in a DD, because we cannot trust Koha : each time we click on pdf, it is generated dynamicly. So if a record is changed, or suppressed, the pdf of the basketgroup is altered... This is not good  : as basketgroups are sent to booksellers, they are not supposed to change, except if we want so.

Maybe it deserves a message in Koha-devel...

M. Saby
Comment 21 mathieu saby 2013-09-17 22:51:27 UTC
What I am planning ; 
- making an other patch for displaying deleted records in acq module (Bug 10758 + discussion on koha-devel)

- create an alert in this bug.

I think we should not forbid the suppression of records used in acq module, because documents could have been withdrawn and libraries could rightfully want to delete the record.
BUT 
-we must have a strong warn, particularly while 10758 is not pushed (and I don't know when it will be, since it is not written yet!).
-only ppl with acq permission should have rights to suppress the record

So I think we could : 
- make a simple, strong warn for ppl with acq rights : "Warning : deleting the record will cause severe issues in basket display"
- make an other message for ppl without acq permissions "You cannot delete this record. You need acq rghts"
- work on 10758
- when 10758 is pushed (some weeks ago maybe), make an other patch, to change the warn message, and maybe try to be more subtle (for ex, giving the choice of deleting the order while deleting the record, or allowing to delete only cancelled records, etc).

M. Saby
Comment 22 mathieu saby 2013-09-19 15:57:54 UTC Comment hidden (obsolete)
Comment 23 I'm just a bot 2013-09-24 05:39:17 UTC
Patch applied cleanly, go forth and signoff
Comment 24 Pierre Angot 2013-09-26 09:50:54 UTC
Is it a duplicate of 10869 ? It seems redundant.
Comment 25 mathieu saby 2013-09-26 09:55:10 UTC
Not really
10869 fixes a bug in basket pages
9780 prevent a dangerous behavior in catalog pages

Mathieu
Comment 26 Pierre Angot 2013-10-17 07:46:50 UTC
I think there is a problem when your items are created when placing an order. I've suppressed item associated to record A. There is no message which warn you that this items is used in an order.

It's a big problem. When AcqCreateItem is "when placing an order", if you suppress the item, you cannot add a new one to the order. You must delete the order or create a new one.
It will be good if there is a new condition linked to this syspref.
Comment 27 mathieu saby 2013-10-17 08:20:26 UTC
Indeed, I did not try to use the patch with items created when placing an order.
So there can be an issue with this pref.
I put it in Failed QA and will take a look at it later.

Thank you for testing
Comment 28 mathieu saby 2013-10-17 19:42:13 UTC
I read again your comment. In fact everything is OK for me : 
The goal of the patch is to prevent the suppression of RECORDS used in orders, not the suppression of ITEMS used in orders.

So the behavior is unchanged for items : you can still suppres an item created by an order, without any warns, like before the patch. It is bad, but it must be fixed in an other patch, as it is not exactly the same problem.

Do you agree with that?

I put patch to need sign off again.

Mathieu
Comment 29 mathieu saby 2013-10-17 19:44:11 UTC
If you agree and if the other points of the test plan were ok for you, you can sign it off.

Mathieu
Comment 30 Pierre Angot 2013-10-18 15:53:53 UTC
Well, I'm agree and disagree ^^

I'm ok with the goal. It's fine, but I prefer having a warn message on item deletion when AcqCreateItem is "when placing an order".

You've mentionned a new patch. It will be a good thing if this new patch blocks this one.

Is it possible ? It's easy to test on sandbox, I can sign both of them rapidly.
Comment 31 Paul Poulain 2013-10-18 16:47:42 UTC
Just for the record: this problem (and the items one) was discussed yesterday at KohaCon13 acquisition roundtable.
Comment 32 mathieu saby 2013-10-19 12:08:57 UTC
(In reply to Pierre Angot from comment #30)
> Well, I'm agree and disagree ^^
> 
> I'm ok with the goal. It's fine, but I prefer having a warn message on item
> deletion when AcqCreateItem is "when placing an order".
> 
> You've mentionned a new patch. It will be a good thing if this new patch
> blocks this one.
> 
> Is it possible ? It's easy to test on sandbox, I can sign both of them
> rapidly.

Hi Pierre
I agree that an other patch could be made for improving Koha's behavior when you try to supprss items, but : 
1/ it is better to write small patches, each one adressing a specific issue (even if we can link bugs together or maybe create a wiki page for grouping patches about the same kind of issue). More easy and quicker to test, sign off and QA.
2/ the patch for adding warnings when you suppress items is not written yet
3/ maybe the logic for this new patch should be slightly different from 9780, so we need to make some specifications first, have discussion, etc, and it will take time - wile 9780 is already signable.
4/ as Paul Poulain wrote in a message to french list recently, there's necessarily a "selfish" dimension behind community involvment, especially when you write patches on week-ends, not beeing paid for that (and you know that's my case). So I wrote this one for "my" librarians, because for us - we create items at receipt - deleting records linked with orders is a bigger issue than deleting items linked with orders. Maybe I could have time to write the other, maybe not...

For all those reasons, I say to "Signe, boulet!"

Mathieu
Comment 33 mathieu saby 2013-10-19 12:11:25 UTC
(In reply to Paul Poulain from comment #31)
> Just for the record: this problem (and the items one) was discussed
> yesterday at KohaCon13 acquisition roundtable.

Of course, Paul, if you have arguments against signing this patch you can expose them.
Or, maybe, if the patch is working, let it be signed off, and you could make its QA and tell us if my logic is not good ?

Mathieu
Comment 34 Pierre Angot 2013-10-19 12:27:26 UTC
Ha ha ha !

I've got an idea : go to your Syspref, select AcqCreateItem and change it to "when placing an order". You are know in the same situation as me :p

Well, I must do a complete test before signing it.
Comment 35 mathieu saby 2013-10-19 12:37:12 UTC
(In reply to Pierre Angot from comment #34)
> Ha ha ha !
> 
> I've got an idea : go to your Syspref, select AcqCreateItem and change it to
> "when placing an order". You are know in the same situation as me :p
> 
I've done it to check my patch was not making things worse for "when placing an order" syspref ;-)
But I think it does not make things worse in that case, it has just no effect when tou suppress the items.
But when the items are suppress, you still have the same warning if you try to delete the record. So it is usefull even with "when placing an order" syspref.

Mathieu
Comment 36 Paul Poulain 2013-10-19 14:39:51 UTC
(In reply to mathieu saby from comment #33)
> (In reply to Paul Poulain from comment #31)
> > Just for the record: this problem (and the items one) was discussed
> > yesterday at KohaCon13 acquisition roundtable.
> 
> Of course, Paul, if you have arguments against signing this patch you can
> expose them.
> Or, maybe, if the patch is working, let it be signed off, and you could make
> its QA and tell us if my logic is not good ?
I've no arguments against it, it's the opposite: during the round table librarians where complaining of this problem, I just said "hey, but, there's a patch for this one" !

Pierre (Mathieu, implying that "pierre" is a "boulet" is funny :D :D :D ), let's sign off & i'll QA tomorrow, during the hackfest.

[ For now, let's head to the bus going to Lake Tahoe (http://www.visitinglaketahoe.com/) ! ]
Comment 37 Pierre Angot 2013-10-19 17:49:39 UTC
All the tests are ok.

There is a little problem in test plan : if you unckeck "order manage", you can't created basket :p I mentionned only if someone wants do some other test. 

The second part :

B. test what can do and see a librarian without order managing rights
4) Connect to Koha with a borrower with order managing rights
5) in a basket, create 2 orders A & B from new records
6) delete order B
7) Logoff and connect to Koha with a borrower without order managing rights
8) in the catalogue, try to suppress
- record used for order A : you should see a specific warning informing you you need specific rights to suppress the record
- record used for order B : idem
- a record not used in any order : you should see no specific warning


PS : we need a same warn on items when AcqCreateItem is "when placing an order" :p
Comment 38 mathieu saby 2013-10-19 18:30:33 UTC
(In reply to Pierre Angot from comment #37)
> All the tests are ok.
> 
> There is a little problem in test plan : if you unckeck "order manage", you
> can't created basket :p I mentionned only if someone wants do some other
> test. 
> 
> The second part :
> 
> B. test what can do and see a librarian without order managing rights
> 4) Connect to Koha with a borrower with order managing rights
> 5) in a basket, create 2 orders A & B from new records
> 6) delete order B
> 7) Logoff and connect to Koha with a borrower without order managing rights
> 8) in the catalogue, try to suppress
> - record used for order A : you should see a specific warning informing you
> you need specific rights to suppress the record
> - record used for order B : idem
> - a record not used in any order : you should see no specific warning
> 
> 
> PS : we need a same warn on items when AcqCreateItem is "when placing an
> order" :p

Thank you Pierre. You are definitely my FAVORITE boulet.
Mathieu
Comment 39 mathieu saby 2013-10-20 09:29:46 UTC
Pierre, new bug created for the issue you pointed out:
Bug 11082

Mathieu
Comment 40 mathieu saby 2013-10-20 09:31:10 UTC
By the way, Bug 10758 is more or less related to the same issue (show title/author from deletedbiblio when the biblio is deleted). And of course the same could be done with items/deleteditems if it is relevant.

Mathieu
Comment 41 Paul Poulain 2013-10-20 23:07:59 UTC
QA comments:
 * passes koha-qa.pl
 * translatable strings are correctly managed
 * works as expected
 * handles nicely various cases, depending on the permissions the librarian has

well done

passed QA
Comment 42 Paul Poulain 2013-10-20 23:09:46 UTC
Created attachment 22128 [details] [review]
Bug 9780 : Restric the right to suppress a record used in some order

Currently, anyone can suppress a record used in an order.
With this patch, only librarians with managing order permission can suppress it if it is used in an active or a deleted order.
This patch also add a specific warning informing that deleting a record used in an active order is dangerous.

To test :
A. test what can do and see a librarian with order managing rights
0) Connect to Koha with a borrower with order managing rights
1) in a basket, create 2 orders A & B from new records
2) delete order B
3) in the catalogue, try to suppress
- record used for order A : you should see a specific warning informing you the record is used in 1 order, and that deleting it is dangerous
- record used for order B : you should see a specific warning informing you the record is used in 1 deleted order
- a record not used in any order : you should see no specific warning

B. test what can do and see a librarian without order managing rights
4) Connect to Koha with a borrower without order managing rights
5) in a basket, create 2 orders A & B from new records
6) delete order B
7) in the catalogue, try to suppress
- record used for order A : you should see a specific warning informing you you need specific rights to suppress the record
- record used for order B : idem
- a record not used in any order : you should see no specific warning

Signed-off-by: Pierre Angot <tredok.pierre@gmail.com>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
Comment 43 Katrin Fischer 2013-10-20 23:27:11 UTC
There is one small thing with this \n in the message will create trouble in Pootle and can't be translated correctly to be line breaks. What I would do is split those messages up or take the \n out.
Comment 44 mathieu saby 2013-10-21 06:09:21 UTC
(In reply to Katrin Fischer from comment #43)
> There is one small thing with this \n in the message will create trouble in
> Pootle and can't be translated correctly to be line breaks. What I would do
> is split those messages up or take the \n out.


I cannot deal with today. we can get rid of /n.
I have seen /n in other javascript alert in Koha. Is it something to fix?

Mathieu
Comment 45 Katrin Fischer 2013-10-21 13:38:14 UTC
If they are not in a translated string it shouldn't cause problems. Ex.
$string .= "\n--------------------------------";
The problem is that Pootle seems to escape those automatically, so you end up with a printed \n in translations (or at least it used to).
Comment 46 mathieu saby 2013-10-21 17:23:34 UTC
(In reply to Katrin Fischer from comment #45)
> If they are not in a translated string it shouldn't cause problems. Ex.
> $string .= "\n--------------------------------";
> The problem is that Pootle seems to escape those automatically, so you end
> up with a printed \n in translations (or at least it used to).

I'm suppressing that.
But a grep gave me an other '\n' in js in modules/calendar.inc. Maybe it needs to be fixed too.
Comment 47 mathieu saby 2013-10-21 17:30:54 UTC
Created attachment 22168 [details] [review]
[PATCH 2] Bug 9780 QA Followup : suppress line feeds in javascript

This patch suppress \n in javascript, in order to keep Pootle quiet.

String patch, no need to test I think.
But if you want to test, replay the test plan of main patch, and check the messages in javascript alert are displaying the right way.
Comment 48 Paul Poulain 2013-10-21 18:11:53 UTC
(In reply to mathieu saby from comment #47)
> String patch, no need to test I think.
> But if you want to test, replay the test plan of main patch, and check the
> messages in javascript alert are displaying the right way.
I've reviewed your patch, it's \n removal only, passed QA still valid imo
Comment 49 Galen Charlton 2013-11-01 00:02:36 UTC
Pushed to master.  Thanks, Mathieu!