Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-66032

Adding an empty 'Awarded badges' criterion to a badge throws dml exception.

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Setup

      1. Perform these steps with the patch not applied (before patch).
      2. Login as an admin user.
      3.  GOTO Site Administration->Development->Make test course
      4. Name it whatever you like, and select S (small) for the size.
      5. Click 'create course'
      6. GOTO Site Administration->SCROLL to Badges->CLICK Add a new badge.
      7. Name it 'Valid Badge' and give it any description, icon and issuer.
      8. CLICK the dropdown to add criteria, and select 'Manual issue by role'
      9. Select any of the roles (at least one) and click save
      10. Click 'Enable Access'
      11. Click 'Continue' on Changes to badge access pop up.
      12. The badge should have been created without any errors. (This badge will be used later)

      Test that existing badges with an empty 'awarded badges' criteria will not throw an error.

      1. Continue with the patch not applied (before patch).
      2. GOTO Site Administration->SCROLL to Badges->CLICK Add a new badge.
      3. Name it 'Invalid Badge' and give it any description, icon and issuer.
      4. CLICK the dropdown to add criteria, and select 'Manual issue by role'
      5. Select any of the roles (at least one) and click save
      6. Click 'Enable Access'
      7. Before patch operations ended. reset to patch applied (after patch)
      8. Click 'Continue' on Changes to badge access pop up.
      9. Verify the badge has been created without any errors. This is to show that legacy badges with incorrect criteria will not throw an exception.

      Test that new 'awarded badges' criteria cannot be created with an empty list.

      1. Continue with the patch applied (after patch).
      2. GOTO Site Administration->SCROLL to Badges->CLICK Add a new badge.
      3. Name it 'Empty Award Badge' and give it any description, icon and issuer.
      4. CLICK the dropdown to add criteria, and select 'Awarded badges'
      5. CLICK Save without selecting anything else. Note that at least one other badge must have already been created and activated.
      6. Verify that a message pops up saying you must select a badge.
      7. Verify that you are not navigated from the same screen.
      Show
      Setup Perform these steps with the patch not applied (before patch). Login as an admin user.  GOTO Site Administration->Development->Make test course Name it whatever you like, and select S (small) for the size. Click 'create course' GOTO Site Administration->SCROLL to Badges->CLICK Add a new badge. Name it 'Valid Badge' and give it any description, icon and issuer. CLICK the dropdown to add criteria, and select 'Manual issue by role' Select any of the roles (at least one) and click save Click 'Enable Access' Click 'Continue' on Changes to badge access pop up. The badge should have been created without any errors. (This badge will be used later) Test that existing badges with an empty 'awarded badges' criteria will not throw an error. Continue with the patch not applied (before patch). GOTO Site Administration->SCROLL to Badges->CLICK Add a new badge. Name it 'Invalid Badge' and give it any description, icon and issuer. CLICK the dropdown to add criteria, and select 'Manual issue by role' Select any of the roles (at least one) and click save Click 'Enable Access' Before patch operations ended. reset to patch applied (after patch) Click 'Continue' on Changes to badge access pop up. Verify the badge has been created without any errors. This is to show that legacy badges with incorrect criteria will not throw an exception. Test that new 'awarded badges' criteria cannot be created with an empty list. Continue with the patch applied (after patch). GOTO Site Administration->SCROLL to Badges->CLICK Add a new badge. Name it 'Empty Award Badge' and give it any description, icon and issuer. CLICK the dropdown to add criteria, and select 'Awarded badges' CLICK Save without selecting anything else. Note that at least one other badge must have already been created and activated. Verify that a message pops up saying you must select a badge. Verify that you are not navigated from the same screen.
    • Affected Branches:
      MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
    • Fixed Branches:
      MOODLE_36_STABLE, MOODLE_37_STABLE
    • Pull 3.6 Branch:
      MDL-66032-MOODLE_36_STABLE_awarded_badges_criteria
    • Pull 3.7 Branch:
      MDL-66032-MOODLE_37_STABLE_awarded_badges_criteria
    • Pull Master Branch:
      MDL-66032-master_awarded_badges_criteria

      Description

      Currently, it is possible to add the 'Awarded badges' criterion to a new badge without attaching any badges. This causes an exception to be thrown when activating the badge, and when the badge cron task is run.

      It is also possible to add the 'Awarded badges' criterion with badges attached and then afterwards remove all of the badges.

      If a badge has the 'awarded badges' criteria without any badges associated, it is equivalent to not having the criteria at all. The criteria should not be able to be created without badges selected, or edited so that no badges are selected. However, no exception should be thrown for badges that have an 'empty list' for this criteria.

      To reproduce the issue:

      Setup

      1. Login as an admin user.
      2.  GOTO Site Administration->Development->Make test course
      3. Name it whatever you like, and select S (small) for the size.
      4. Click 'create course'
      5. GOTO Site Administration->SCROLL to Badges->CLICK Add a new badge.
      6. Name it 'Valid Badge' and give it any description, icon and issuer.
      7. CLICK the dropdown to add criteria, and select 'Manual issue by role'
      8. Select any of the roles and click save
      9. Click 'Enable Access'
      10. Click 'Continue' on Changes to badge access pop up.
      11. The badge should have been created without any errors. (This badge will be used later)

      Create badge without criteria

      1. GOTO Site Administration->SCROLL to Badges->CLICK Add a new badge.
      2. Name it 'Empty Award Badge' and give it any description, icon and issuer.
      3. CLICK the dropdown to add criteria, and select 'Awarded badges'
         # CLICK Save without selecting anything else. Note that at least one other badge must have already been created and activated.
      4. CLICK 'Enable Access'
      5. CLICK 'Continue' on Changes to badge access pop up.
      6. Verify that an sql exception has been thrown.

      Create badge with valid 'awarded badges' criteria, then remove prerequisite badges

      1. GOTO Site Administration->SCROLL to Badges->CLICK Add a new badge.
      2. Name it 'Removed Award Badge' and give it any description, icon and issuer.
      3. CLICK the dropdown to add criteria, and select 'Awarded badges'
      4. CLICK on 'Valid Badge' in the list. (Created in setup)
      5. CLICK Save.
      6. CLICK on the gear wheel next to the 'Awarded badges' criteria to open settings.
      7. CTRL-CLICK on the 'Valid Badge' in the list.
      8. CLICK Save.
      9. CLICK 'Enable Access'
      10. CLICK 'Continue' on Changes to badge access pop up.
      11. Verify that an sql exception has been thrown.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  13/May/19

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 hours, 5 minutes
                  2h 5m