openedx / edx-platform

The Open edX LMS & Studio, powering education sites around the world!
https://openedx.org
GNU Affero General Public License v3.0
7.34k stars 3.84k forks source link

Create XBlock permissions for `can_view_answer`, `can_view_correctness` #33325

Open ormsbee opened 12 months ago

ormsbee commented 12 months ago

The ProblemBlock has some sophisticated logic for determining whether the user should be allowed to see the answer (and also whether they were correct or not):

https://github.com/openedx/edx-platform/blob/f9148f032fc93bd339fb0ab50afb5cb3b1cdca21/xmodule/capa_block.py#L1400-L1457

This has been partially re-implemented in other XBlocks over time. We should refactor this into a runtime service that will return a simple True/False for this question, so that we can get consistent behavior without other XBlock authors having to think about it.

steff456 commented 11 months ago

Hi @ormsbee

I'm currently working in this issue and wanted to double check with you if the idea is to create a service as the ones described in openedx/core/djangoapps/xblock/runtime/runtime.py on line 231.

If not, can you please explain to me how should I create the new runtime service?

Thanks a lot!

ormsbee commented 11 months ago

@steff456: Yes, those are what I meant. Another place to find a list of example services is in the LMS rendering code:

https://github.com/openedx/edx-platform/blob/b353019c3f217a64e9baec2394630a98be361d10/lms/djangoapps/courseware/block_render.py#L588-L638

Just a word of warning that this service would need to be instantiated in multiple places, like:

(It might be useful to look for instantiations of DjangoXBlockUserService to see different places where the runtime can get initialized.)