-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🪲 Show unsubmit button to teachers only for programs of their current students #6023
Conversation
24b5f61
to
539b492
Compare
app.py
Outdated
second_teachers = [t for t in class_.get('second_teachers', []) if t.get('role', '') == 'teacher'] | ||
all_teachers = [class_.get('teacher')] + [t.get('username', '') for t in second_teachers] | ||
arguments_dict['is_students_teacher'] = user.get('username') in all_teachers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a concept here that I'd like to see expressed in code rather than procedurally. This:
def students_teachers(student):
...
def is_students_teacher(student, teacher):
return teacher in students_teachers(student)
If we make it a function, we can reuse the same logic in other places. I'm sure the exact same logic is going to be used somewhere where we determine if a user can view a saved program, no?
def can_view_program(user, program):
return program['owner'] == user or is_students_teacher(program['owner'], user)
Right now, what do we do for determining whether a program is viewable by someone?
In all cases of code everywhere, I would encourage thinking about the fundamental operations that are being done and making functions out of them, rather than pasting in more lines of just-so data structure manipulation.
3aa1708
to
5055ada
Compare
5055ada
to
c1c9296
Compare
Thanks for making the change! It occurred to me that this check, or one like it, must already have happened when we determine whether or not the current user is allowed to look at this program in the first place. And indeed, it happens here: Lines 2939 to 2960 in ac62a54
This means we're now calling To save on this, can we instead return some more information from Can we return something like: {
"can_view": True|False,
"can_change": True|False,
} Instead, and use that? Or maybe a ternary or enum, to express the states This might require changing the order of the conditions in
|
I made the change you requested but this is not a good state to leave the codebase. If I understand correctly, submitting/unsubmitting/checking(which is kind of like approving) a program is not the same as editing it. The program page has an Additionally, the only way to see program page is if the program is public. Of course, you can hit the URL directly, but if you are only using the interface of Hedy, you will not end up on this page unless it is public. So, we do not call the get_student_teachers-like logic twice. At the same time, this page is currently the only one requiring can_unsubmit access. All other uses of the Please let me know if my assumptions about the functionality are correct and, also, how you would like me to proceed. |
Fair enough. Maybe there are 4 levels of permissions: On the other hand, @dataclass
class ProgramPermissions:
can_unsubmit: bool
can_checkoff: bool
can_edit: bool
can_checkoff = is_teacher
can_edit = is_author
can_unsubmit = is_author or is_teacher or is_admin The presence of a value indicates
If I'm understanding it correctly:
So to my understanding, a program being public isn't the only way to end up here?
But didn't it use to look like this: def view_program():
# This wraps a call to check whether the current user is a teacher of the author
if not result or not current_user_allowed_to_see_program(result):
return utils.error_page(error=404, ui_message=gettext('no_such_program'))
# ...
# Second call to c heck whether the current user is a teacher of the author
arguments_dict['is_students_teacher'] = is_students_teacher(student=result['username'], teacher=user['username'])
# ... Am I misreading something?
Fair enough, you are saying that for public programs, we are now doing a database lookup to determine whether we can view a program, even if we didn't need to know whether we can unsubmit it. But I think we can deal with that another way: right now we are doing the database query to see if the current user is the teacher of someone unconditionally, even if the current user is not a teacher (and the database lookup would presumably always return We could simplify it by not doing the lookup unless |
Apologies for the extra detailed discussion, but I need to get this straight because the teachers panel the current pain-point. Based on your comment, I figured that if I am a teacher I can see a non-public, non-submitted program of a student via For Teachers > Class and then use the eye icon in the Student's Adventures table. However, if I am a student, I click on
You are not misreading. My comment was based on the assumption that the view-program-page is for public programs. Overall, I am confused about the the possible states of programs, the grading mechanism and overall about the teachers' panel. Sorry about that. Other than that, I made the changes you requested. |
It's very likely that I am the one missing something here. To confirm, because I trust you have a better view on this than I do:
Does that seem (weird but) accurate to you? While the different views that are being used for these code paths seem a bit odd to me, I'd like to have the "what code makes decisions" and "how we render it" on different axes. And especially the code that makes decisions should be centralized as much as possible, so it's in one obvious place if we ever need to change rules. So I still feel confident that the changes we're making are for the better. What do you think? |
Yes, of course, having common access rules is a natural choice. Thanks for pointing out there are other paths to the program page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork). |
This PR makes 3 changes:
Fixes #5990
How to test
Test user permissions
Check whether you agree with the layout. Please note that this page uses too many headings, different styles and overall does not look stylistically coherent. I intentionally made the minimal changes in the layout without changing styling. It would be great to improve its look and feel in the future. I can also revert all layout changes, as I am not sure whether the new layout is better than the old one.
This is how a submitted program looks if you are a teacher of the student:
And this is how if looks when you are another student or a teacher who is not in the student's class:
Note that when you unsubmit a program, the UI should be updated, so that you cannot unsubmit an already unsubmitted program.