Fossil SCM
Fix an incorrect argument bug in forumpost_tag() which caused it to re-apply tags even if doing so would reapply the same value. The the test-forumpost-tag command. Minor www/forum.wiki touchups.
Commit
ab52bc833121dcc1e7d58a5f7bb2d600307cf942b8fc02df11349198b27cce06
Parent
598d45f816991ec…
2 files changed
+40
-6
+7
-6
+40
-6
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -410,15 +410,13 @@ | ||
| 410 | 410 | ** no tag is added. Similarly, it will only remove a tag from a post |
| 411 | 411 | ** which has its own tag, and will not remove an inherited one from a |
| 412 | 412 | ** parent post. |
| 413 | 413 | ** |
| 414 | 414 | ** If addTag is true and frid is already tagged, this is a |
| 415 | -** no-op. Likewise, if addTag is false and frid is not tagged | |
| 416 | -** (not accounting for an inherited closed tag), this is a no-op. | |
| 417 | -** | |
| 418 | -** If bCheckIrt is true then the forum post IRT hierarchy is searched | |
| 419 | -** for the tag, otherwise only the given RID is checked. | |
| 415 | +** no-op. Likewise, if addTag is false and frid is not tagged (not | |
| 416 | +** accounting for a tag inherited via an in-response-to post), this is | |
| 417 | +** a no-op. | |
| 420 | 418 | ** |
| 421 | 419 | ** Returns a positive value (a new tag.tagid value) if it actually |
| 422 | 420 | ** creates a new tag, else 0. On error it returns a negative alue |
| 423 | 421 | ** and g.zErrMsg "should" contain details. |
| 424 | 422 | ** |
| @@ -465,11 +463,11 @@ | ||
| 465 | 463 | zValue = 0; |
| 466 | 464 | } |
| 467 | 465 | if( addTag && iTagged ){ |
| 468 | 466 | char *zOld = 0; |
| 469 | 467 | int cmp; |
| 470 | - rid_has_tag2(iTagged, zTagName, &zOld); | |
| 468 | + rid_has_tag2(frid, zTagName, &zOld); | |
| 471 | 469 | cmp = fossil_strcmp(zOld, zValue); |
| 472 | 470 | fossil_free(zOld); |
| 473 | 471 | if( 0==cmp ){ |
| 474 | 472 | /* Same value - leave it as is. */ |
| 475 | 473 | db_end_transaction(0); |
| @@ -498,10 +496,46 @@ | ||
| 498 | 496 | zUuid, addTag ? '*' : '-', zTagName); |
| 499 | 497 | fossil_free(zUuid); |
| 500 | 498 | db_end_transaction(0); |
| 501 | 499 | return trid; |
| 502 | 500 | } |
| 501 | + | |
| 502 | +/* | |
| 503 | +** COMMAND: test-forumpost-tag | |
| 504 | +** | |
| 505 | +** Usage: %fossil test-forumpost-tag ?-cancel? THREADID TAGNAME TAGVAL | |
| 506 | +** | |
| 507 | +** A tester for forumpost_tag(). It always rolls back changes. | |
| 508 | +*/ | |
| 509 | +void test_forumpost_tag_command(void){ | |
| 510 | + int fpid; | |
| 511 | + int rc; | |
| 512 | + const char *zPost; | |
| 513 | + const char *zTag; | |
| 514 | + const char *zVal; | |
| 515 | + const int bAdd = find_option("cancel","",0)==0; | |
| 516 | + | |
| 517 | + db_find_and_open_repository(0,0); | |
| 518 | + verify_all_options(); | |
| 519 | + if( g.argc<5 ){ | |
| 520 | + usage("forum-post-id tag-name value"); | |
| 521 | + } | |
| 522 | + zPost = g.argv[2]; | |
| 523 | + zTag = g.argv[3]; | |
| 524 | + zVal = g.argv[4]; | |
| 525 | + | |
| 526 | + db_begin_transaction(); | |
| 527 | + fpid = forumpost_head_rid2(zPost); | |
| 528 | + if( fpid<=0 ){ | |
| 529 | + fossil_fatal("Cannot resolve post ID %s", zPost); | |
| 530 | + } | |
| 531 | + fossil_print("%s => %d => %z\n", zTag, fpid, | |
| 532 | + rid_to_uuid(fpid)); | |
| 533 | + rc = forumpost_tag(fpid, bAdd, zTag, zVal); | |
| 534 | + fossil_print("tag fpid=%d taxgxref.tagid=%d\n", fpid, rc); | |
| 535 | + db_end_transaction(1); | |
| 536 | +} | |
| 503 | 537 | |
| 504 | 538 | /* |
| 505 | 539 | ** Returns true if the forum-close-policy setting is true, else false, |
| 506 | 540 | ** caching the result for subsequent calls. |
| 507 | 541 | */ |
| 508 | 542 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -410,15 +410,13 @@ | |
| 410 | ** no tag is added. Similarly, it will only remove a tag from a post |
| 411 | ** which has its own tag, and will not remove an inherited one from a |
| 412 | ** parent post. |
| 413 | ** |
| 414 | ** If addTag is true and frid is already tagged, this is a |
| 415 | ** no-op. Likewise, if addTag is false and frid is not tagged |
| 416 | ** (not accounting for an inherited closed tag), this is a no-op. |
| 417 | ** |
| 418 | ** If bCheckIrt is true then the forum post IRT hierarchy is searched |
| 419 | ** for the tag, otherwise only the given RID is checked. |
| 420 | ** |
| 421 | ** Returns a positive value (a new tag.tagid value) if it actually |
| 422 | ** creates a new tag, else 0. On error it returns a negative alue |
| 423 | ** and g.zErrMsg "should" contain details. |
| 424 | ** |
| @@ -465,11 +463,11 @@ | |
| 465 | zValue = 0; |
| 466 | } |
| 467 | if( addTag && iTagged ){ |
| 468 | char *zOld = 0; |
| 469 | int cmp; |
| 470 | rid_has_tag2(iTagged, zTagName, &zOld); |
| 471 | cmp = fossil_strcmp(zOld, zValue); |
| 472 | fossil_free(zOld); |
| 473 | if( 0==cmp ){ |
| 474 | /* Same value - leave it as is. */ |
| 475 | db_end_transaction(0); |
| @@ -498,10 +496,46 @@ | |
| 498 | zUuid, addTag ? '*' : '-', zTagName); |
| 499 | fossil_free(zUuid); |
| 500 | db_end_transaction(0); |
| 501 | return trid; |
| 502 | } |
| 503 | |
| 504 | /* |
| 505 | ** Returns true if the forum-close-policy setting is true, else false, |
| 506 | ** caching the result for subsequent calls. |
| 507 | */ |
| 508 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -410,15 +410,13 @@ | |
| 410 | ** no tag is added. Similarly, it will only remove a tag from a post |
| 411 | ** which has its own tag, and will not remove an inherited one from a |
| 412 | ** parent post. |
| 413 | ** |
| 414 | ** If addTag is true and frid is already tagged, this is a |
| 415 | ** no-op. Likewise, if addTag is false and frid is not tagged (not |
| 416 | ** accounting for a tag inherited via an in-response-to post), this is |
| 417 | ** a no-op. |
| 418 | ** |
| 419 | ** Returns a positive value (a new tag.tagid value) if it actually |
| 420 | ** creates a new tag, else 0. On error it returns a negative alue |
| 421 | ** and g.zErrMsg "should" contain details. |
| 422 | ** |
| @@ -465,11 +463,11 @@ | |
| 463 | zValue = 0; |
| 464 | } |
| 465 | if( addTag && iTagged ){ |
| 466 | char *zOld = 0; |
| 467 | int cmp; |
| 468 | rid_has_tag2(frid, zTagName, &zOld); |
| 469 | cmp = fossil_strcmp(zOld, zValue); |
| 470 | fossil_free(zOld); |
| 471 | if( 0==cmp ){ |
| 472 | /* Same value - leave it as is. */ |
| 473 | db_end_transaction(0); |
| @@ -498,10 +496,46 @@ | |
| 496 | zUuid, addTag ? '*' : '-', zTagName); |
| 497 | fossil_free(zUuid); |
| 498 | db_end_transaction(0); |
| 499 | return trid; |
| 500 | } |
| 501 | |
| 502 | /* |
| 503 | ** COMMAND: test-forumpost-tag |
| 504 | ** |
| 505 | ** Usage: %fossil test-forumpost-tag ?-cancel? THREADID TAGNAME TAGVAL |
| 506 | ** |
| 507 | ** A tester for forumpost_tag(). It always rolls back changes. |
| 508 | */ |
| 509 | void test_forumpost_tag_command(void){ |
| 510 | int fpid; |
| 511 | int rc; |
| 512 | const char *zPost; |
| 513 | const char *zTag; |
| 514 | const char *zVal; |
| 515 | const int bAdd = find_option("cancel","",0)==0; |
| 516 | |
| 517 | db_find_and_open_repository(0,0); |
| 518 | verify_all_options(); |
| 519 | if( g.argc<5 ){ |
| 520 | usage("forum-post-id tag-name value"); |
| 521 | } |
| 522 | zPost = g.argv[2]; |
| 523 | zTag = g.argv[3]; |
| 524 | zVal = g.argv[4]; |
| 525 | |
| 526 | db_begin_transaction(); |
| 527 | fpid = forumpost_head_rid2(zPost); |
| 528 | if( fpid<=0 ){ |
| 529 | fossil_fatal("Cannot resolve post ID %s", zPost); |
| 530 | } |
| 531 | fossil_print("%s => %d => %z\n", zTag, fpid, |
| 532 | rid_to_uuid(fpid)); |
| 533 | rc = forumpost_tag(fpid, bAdd, zTag, zVal); |
| 534 | fossil_print("tag fpid=%d taxgxref.tagid=%d\n", fpid, rc); |
| 535 | db_end_transaction(1); |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | ** Returns true if the forum-close-policy setting is true, else false, |
| 540 | ** caching the result for subsequent calls. |
| 541 | */ |
| 542 |
+7
-6
| --- www/forum.wiki | ||
| +++ www/forum.wiki | ||
| @@ -474,22 +474,23 @@ | ||
| 474 | 474 | rendering a newer version. |
| 475 | 475 | |
| 476 | 476 | Caveat: a "closed" status is not recommended because it's easy to confuse with |
| 477 | 477 | the <a href='#close-post'>"closed" tag feature</a>, which behaves considerably |
| 478 | 478 | differently and predates that "status" tag support by about three years. The |
| 479 | -"closed" semantics cannot be trivially consolidated with those of "status". | |
| 479 | +"closed" semantics cannot be trivially consolidated with those of "status" | |
| 480 | +but we reserve the right to do so at some point. | |
| 480 | 481 | |
| 481 | 482 | <h2 name="attachments">Attachments</h2> |
| 482 | 483 | |
| 483 | -As of version 2.29 users with the [./caps/index.md|'B' capability] | |
| 484 | -may attach files to forum posts. Files may not be attached until a | |
| 485 | -forum post is saved for the first time, after which an "Attach" button | |
| 486 | -will appear in the post when it is selected. Attached files undergo | |
| 484 | +As of version 2.29 users with the [./caps/index.md|'B' capability] may | |
| 485 | +attach files to forum posts. Files may not be attached until a forum | |
| 486 | +post is saved for the first time, after which an "Attach" button will | |
| 487 | +appear in the post when it is selected. Attached files undergo | |
| 487 | 488 | moderation exactly like forum posts do. When a moderator accepts a |
| 488 | 489 | pending-moderation posts, all files attached to it which are also |
| 489 | 490 | pending approval are also approved. Similarly, when a moderator |
| 490 | -rejects a pending-moderation post, all files attached to it when are | |
| 491 | +rejects a pending-moderation post, all files attached to it which are | |
| 491 | 492 | also pending approval are rejected. |
| 492 | 493 | |
| 493 | 494 | Developer notes regarding the save-before-attach limitation: |
| 494 | 495 | |
| 495 | 496 | * We cannot add the attachment form to the current post editor |
| 496 | 497 |
| --- www/forum.wiki | |
| +++ www/forum.wiki | |
| @@ -474,22 +474,23 @@ | |
| 474 | rendering a newer version. |
| 475 | |
| 476 | Caveat: a "closed" status is not recommended because it's easy to confuse with |
| 477 | the <a href='#close-post'>"closed" tag feature</a>, which behaves considerably |
| 478 | differently and predates that "status" tag support by about three years. The |
| 479 | "closed" semantics cannot be trivially consolidated with those of "status". |
| 480 | |
| 481 | <h2 name="attachments">Attachments</h2> |
| 482 | |
| 483 | As of version 2.29 users with the [./caps/index.md|'B' capability] |
| 484 | may attach files to forum posts. Files may not be attached until a |
| 485 | forum post is saved for the first time, after which an "Attach" button |
| 486 | will appear in the post when it is selected. Attached files undergo |
| 487 | moderation exactly like forum posts do. When a moderator accepts a |
| 488 | pending-moderation posts, all files attached to it which are also |
| 489 | pending approval are also approved. Similarly, when a moderator |
| 490 | rejects a pending-moderation post, all files attached to it when are |
| 491 | also pending approval are rejected. |
| 492 | |
| 493 | Developer notes regarding the save-before-attach limitation: |
| 494 | |
| 495 | * We cannot add the attachment form to the current post editor |
| 496 |
| --- www/forum.wiki | |
| +++ www/forum.wiki | |
| @@ -474,22 +474,23 @@ | |
| 474 | rendering a newer version. |
| 475 | |
| 476 | Caveat: a "closed" status is not recommended because it's easy to confuse with |
| 477 | the <a href='#close-post'>"closed" tag feature</a>, which behaves considerably |
| 478 | differently and predates that "status" tag support by about three years. The |
| 479 | "closed" semantics cannot be trivially consolidated with those of "status" |
| 480 | but we reserve the right to do so at some point. |
| 481 | |
| 482 | <h2 name="attachments">Attachments</h2> |
| 483 | |
| 484 | As of version 2.29 users with the [./caps/index.md|'B' capability] may |
| 485 | attach files to forum posts. Files may not be attached until a forum |
| 486 | post is saved for the first time, after which an "Attach" button will |
| 487 | appear in the post when it is selected. Attached files undergo |
| 488 | moderation exactly like forum posts do. When a moderator accepts a |
| 489 | pending-moderation posts, all files attached to it which are also |
| 490 | pending approval are also approved. Similarly, when a moderator |
| 491 | rejects a pending-moderation post, all files attached to it which are |
| 492 | also pending approval are rejected. |
| 493 | |
| 494 | Developer notes regarding the save-before-attach limitation: |
| 495 | |
| 496 | * We cannot add the attachment form to the current post editor |
| 497 |