Skip to content

Classroom abilities + create studio + misc #294

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

Merged
merged 45 commits into from
Dec 24, 2024
Merged

Conversation

FAReTek1
Copy link
Collaborator

@FAReTek1 FAReTek1 commented Dec 8, 2024

New classroom abilities

Adds a wide array of capabilities for scratch's classroom system, including:

  • Creating classes
  • Loading closed classes using HTML web scraping
  • Checking if a class is closed
  • Setting thumbnails (also added the ability to set pfps of normal accounts as well)
  • Setting descriptions
  • Setting 'what we're working on'/status
  • Setting class title/name
  • Adding studios
  • Closing/Reopening classes
  • Registering students (NOT FROM CSV) should this be removed?
  • Generating signup link (This actually just uses the class token)
  • Fetching public activity (same format as user activity; loading from HTML)
  • Fetching private activity - things like comments or profile updates (in a bad format which is very improvable)
  • Registering users with simply a class token
  • Abilities to load stuff in classes in different sort modes

Other new abilities

create_studio()

Added the Session.create_studio() function to create studios to solve an issue (#277). I copy+pasted rate limit code from Session.create_project(). Also added title/desc settings to make it more convenient

exceptions

  • Now using the msg argument in exceptions.Unauthorized() so that you can add more detail to the exception if need be. When receiving a 403/401 status code in the requests wrapper, it will now print the request content which will sometimes be more descriptive than simply: "You are unauthorised"
  • Renamed ConnectionError to CloudConnectionError since ConnectionError is actually a builtin error

misc changes/features

  • added password reset email sender (since i was resetting passwords of a lot of my old accounts)
  • A few scratchtools endpoints (isonline, is beta user, scratchtools display name) in other_apis.py
  • Added class option to commons.webscrape_count

Extra Note(s)

  • In cloud_requests.py, I fixed a typo of self.call_even, changing it to self.call_event. In the rare case this is intentional, now you know
  • Also it looks like I pressed ctrl-alt-l again...
  • I added a lot of dosctrings at the start of when I made this, before I knew about from __future__ import annotations so that may need to be fixed

FAReTek1 and others added 30 commits November 9, 2024 20:02
…or is a builtin so i renamed it, also i fixed a typo in cloud_requests.py
Signed-off-by: FA ReTek <107722825+FAReTek1@users.noreply.github.com>
fixed image in pypi info page
@FAReTek1
Copy link
Collaborator Author

more potential features:
actually parse the private activity

This was referenced Dec 21, 2024
@FAReTek1 FAReTek1 changed the title Classroom abilities + create studio Classroom abilities + create studio + misc Dec 21, 2024
@FAReTek1 FAReTek1 added the enhancement New feature or request label Dec 23, 2024
@FAReTek1
Copy link
Collaborator Author

I will add the parser for private class activity first

@FAReTek1
Copy link
Collaborator Author

there is now a parser for the private activity. no parser for alerts tho

@FAReTek1
Copy link
Collaborator Author

here is the reference file i used to build that parser:

<script type="text/template" id="template-activity-list-item">
    <% switch(type)
    { case 0: %>
    <span class="icon-xs black follow"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    followed user
    <a href="/users/<%- followed_username %>"><%- followed_username %></a>

    <% break; case 1:  %>
    <span class="icon-xs black follow"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    followed studio
    <a href="/studios/<%- gallery %>"><%- title %></a>

    <% break; case 2:  %>
    <span class="icon-xs black love"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    loved the project
    <a href="/projects/<%- project %>"><%- title %></a>

    <% break; case 3:  %>
    <span class="icon-xs black favorite"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    favorited the project
    <a href="/projects/<%- project %>"><%- project_title %></a>

    <% break; case 7:  %>
    <span class="icon-xs black project"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    added the project
    <a href="/projects/<%- project %>"><%- project_title %></a>
    to studio
    <a href="/studios/<%- gallery %>"><%- gallery_title %></a>

    <% break; case 8:  %>

    <% break; case 9:  %>

    <% break; case 10:  %>

    <span class="icon-xs black project"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>

    <% if (is_reshare) { %>

    shared the project

    <% } else { %>

    reshared the project

    <% } %>

    <a href="/projects/<%- project %>"><%- title %></a>

    <% break; case 11:  %>

    <span class="icon-xs black project"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    remixed the project
    <a href="/projects/<%- project %>"><%- title %></a>

    <% break; case 13:  %>
    <span class="icon-xs black project"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    added the studio
    <a href="/studios/<%- gallery %>">Untitled Studio</a>

    <% break; case 15:  %>
    <span class="icon-xs black project"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    updated the studio
    <a href="/studios/<%- gallery %>"><%- title %></a>

    <% break; case 16:  %>

    <% break; case 17:  %>

    <% break; case 18:  %>

    <% break; case 19:  %>
    <span class="icon-xs black project"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    removed the project
    <a href="/projects/<%- project %>"><%- project_title %></a>
    from studio
    <a href="/studios/<%- gallery %>"><%- gallery_title %></a>

    <% break; case 20:  %>

    <% break; case 21:  %>

    <% break; case 22:  %>
    <span class="icon-xs black follow"></span>
    <a href="/users/<%- recipient_username %>"><%- recipient_username %></a>
    was promoted to manager by
    <a href="/users/<%- actor_username %>"><%- actor_username %></a>
    for studio
    <a href="/studios/<%- gallery %>"><%- gallery_title %></a>

    <% break; case 23:  %>

    <% break; case 24:  %>

    <% break; case 25:  %>
    <span class="icon-xs black project"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    made a profile update. <em></em>

    <% break; case 26:  %>

    <% break; case 27:  %>
    <span class="icon-xs black comment"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    <% if (comment_type === 0) { %>
        commented on the project
        <a href="/projects/<%- comment_obj_id %>"><%- comment_obj_title %></a>
        <%
        // format the direct link to the comment (used in the comment block below)
        var comment_reply_link = '/projects/' + comment_obj_id + '/#comments-' + comment_id
        %>
    <% } %>

    <% if (comment_type === 1) { %>
        commented on user
        <a href="/users/<%- comment_obj_title %>"><%- comment_obj_title %></a>
        <%
        // format the direct link to the comment (used in the comment block below)
        var comment_reply_link = '/users/' + comment_obj_title + '/#comments-' + comment_id
        %>
        <% } %>

    <% if (comment_type === 2) { %>
        commented on the studio
        <a href="/studios/<%- comment_obj_id %>"><%- comment_obj_title %></a>
        <%
        // format the direct link to the comment (used in the comment block below)
        var comment_reply_link = '/studios/' + comment_obj_id + '/#comments-' + comment_id
        %>
        <% } %>

    <% break; default:  %>
    <span class="icon-xs black project"></span>
    <a href="/users/<%- actor.username %>"><%- actor.username %></a>
    performed an action. <em> <%- type %></em>
    <% break;} %>

    <span class="time"><span class="media-info-item date shortDateFormat last"><%- $.format.date(datetime_created, "MM/dd/yyyy") %></span></span>


    <% if (typeof comment_fragment !== 'undefined') { %>
    <div class="comment-block">
        <span class="comment-text"><%- comment_fragment %></span>
        <a class="reply" href="<%= comment_reply_link %>"> <span>Reply</span> </a>
    </div>
    <% } %>
</script>


<script type="text/template" id="template-alert-list-item">
    <div class="alert-item-content" data-alert-id="<%- id %>">
        <span class="alert-icon small"></span>
        <% switch(admin_action.type)
            { case 0: %>
            <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            banned.

            <% break; case 1: %>
            <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            unbanned.

            <% break; case 2: %>
            <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            excluded from homepage.

            <% break; case 3: %>
            <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            excluded from homepage.

            <% break; case 4: %>
            <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            notified by a Scratch Administrator. Notification Type: <%- admin_action.extra_data.notification_type ||
            'Unknown' %>

            <% break; case 5: %>
            <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            banned automatically.

            <% break; case 6: %>
            <a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
                href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            removed automatically.

            <% break; case 7: %>

            <% case 20: %>
            <a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
                href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            censored.

            <% break; case 8: %>
            <a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
                href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            uncensored.

            <% break; case 9: %>

            <% case 10: %>
            <a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
                href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            reviewed by a Scratch Administrator.

            <% break; case 11: %>
            <a href='/projects/<%- admin_action.object_id %>'><%- admin_action.extra_data.project_title %></a> by <a
                href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            deleted by a Scratch Administrator.

            <% break; case 12: %>
            <% case 17: %>
            <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
            deleted by a Scratch Administrator.

            <% break; case 13: %>

            <% case 14: %>
            <a href='/studios/<%- admin_action.object_id %>'><%- admin_action.extra_data.gallery_title %></a> was reviewed
            by a Scratch Administrator.

            <% break; case 15: %>
            <a href='/studios/<%- admin_action.object_id %>'><%- admin_action.extra_data.gallery_title %></a> was deleted by
            a Scratch Administrator.

            <% break; case 16: %>
            <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> deleted
            their own account.

            <% break; case 18: %>
            The email address of <a href='/users/<%- admin_action.target_user.username %>'><%-
            admin_action.target_user.username %></a> was confirmed by a Scratch Administrator

            <% break; case 19: %>
            The email address of <a href='/users/<%- admin_action.target_user.username %>'><%-
            admin_action.target_user.username %></a> was set as not confirmed by a Scratch Administrator

            <% break; case 22: %>
            <% if(typeof admin_action.extra_data.comment_content == 'undefined'){ %>
                <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
                automatically muted by our comment filters.
            <% } else { %>
                <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> was
                automatically muted by our comment filters. The comment they tried to post was: <i><%-
                admin_action.extra_data.comment_content.content %></i>
            <% } %>

            <% break; default: %>
            <a href='/users/<%- admin_action.target_user.username %>'><%- admin_action.target_user.username %></a> had an
            admin action performed. <em><%- admin_action.type %></em>

            <% break;} %>

            <span class="time"><span class="media-info-item date shortDateFormat last"><%- $.format.date(admin_action.datetime_created, "MM/dd/yyyy") %></span></span>
            <% if(typeof classroom_names !== 'undefined'){ %>
                <div class="alert-classroom-data">Classes: <em><%- classroom_names %></em></div>
            <% } %>
            <% if(this.allowHideAlerts) { %>
                <span data-control="hide-alert" data-message-id="<%= admin_action.message %>" class="delete">x</span>
        <% } %>
    </div>
</script>

Signed-off-by: faretek <107722825+FAReTek1@users.noreply.github.com>
@FAReTek1
Copy link
Collaborator Author

I think that some tester code should be written to make sure that scratchattach is running fine. It makes me very scared whenever I make large merges like this, especially with all of the conflicts that I have to solve

@FAReTek1
Copy link
Collaborator Author

well, as long as it isn't pushed to pypi yet, it is safe to debug and fix?

@FAReTek1
Copy link
Collaborator Author

merging it now reduces the chances of more issues to crop up

@FAReTek1 FAReTek1 merged commit 9432bb1 into TimMcCool:main Dec 24, 2024
@FAReTek1
Copy link
Collaborator Author

i now want to make some tester algorithm that asserts that everything is functioning as usual. however it will be quite complicated to code

@FAReTek1 FAReTek1 deleted the classes branch December 24, 2024 16:57
@FAReTek1
Copy link
Collaborator Author

i realise now, the empty cases are actually relaying onto the next case statement. this needs to be fixed

@FAReTek1
Copy link
Collaborator Author

fixed in my upcoming pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant