Skip to content
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

Add admin view to copy courses from production instance of dashboard (#5528) #5528

Conversation

gabina
Copy link
Member

@gabina gabina commented Nov 7, 2023

What this PR does

This PR creates a new admin view to dump course data from a production dashboard to the local environment.
In order to do this a new copy course service was created, based on the already existing setup/copy_course_from_production.rb command.

The PR also fixes an existing bug on the command related to update_logs keys being parsed as string instead of integers.

Closes #4911

Screenshots

Before:
No admin view

After:
Example of success and failure:

example.webm

Open questions and concerns

There are a lot of duplicated code in setup/copy_course_from_production.rb and the new copy course service. We should either delete the command or make a refactor on it to use the sevice.
It also looks like there is some code duplication in setup/populate_dashboard.rb that we may want to refactor.

@gabina gabina marked this pull request as draft November 7, 2023 03:18
@gabina gabina changed the title [WIP] Add admin view to copy courses from production instance of dashboard [WIP] Add admin view to copy courses from production instance of dashboard (#5528) Nov 7, 2023
@@ -14,21 +14,23 @@
%h2 Useful links
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ordered the links alphabetically

Comment on lines 54 to 58
# When parsing update_logs from flags, keys are set as strings instead of integers
# This causes problems, so we need to force the keys to be integers.
def fix_update_logs_parsing(update_logs)
update_logs.transform_keys(&:to_i)
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of code duplication, do we want to keep this command?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this file should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done on fff45d6

@gabina gabina changed the title [WIP] Add admin view to copy courses from production instance of dashboard (#5528) Add admin view to copy courses from production instance of dashboard (#5528) Nov 7, 2023
@gabina gabina marked this pull request as ready for review November 7, 2023 16:31
@gabina
Copy link
Member Author

gabina commented Nov 7, 2023

@ragesoss this PR is ready for review whenever you have some free time. Failing tests don't seem to be related to the PR changes.

@home_wiki = Wiki.get_or_create(language: @course_data['home_wiki']['language'],
project: @course_data['home_wiki']['project'])
copied_data['home_wiki_id'] = @home_wiki.id
copied_data['passcode'] = 'passcode' # set an arbitrary passcode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we could potential use this in production to copy from one server to another, I think it will be better to use a random passcode via GeneratePasscode.call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done on 65188da

%li
%a{href: '/sidekiq'} Job queue
%a{href: '/copy_course'} Copy Course from Another Dashboard Server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Copy course from another server'. No need for extra capitalization, and I think 'Dashboard' is redundant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done on 048de68

@@ -1,5 +1,5 @@
- if flash[:notice]
.notification= flash[:notice]
.notification= flash[:notice].html_safe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I cherry-picked this from the previous PR.
We are using flash[:notice] for rendering the success message in the controller, and that message has a link to the new course (which is added using <a> tag). It looks like we need to add the html_safe to indicate that the string should be considered safe HTML content and should not be escaped when rendered in a view. Without the html_safe, the link doesn't render properly.

@ragesoss
Copy link
Member

ragesoss commented Nov 7, 2023

This looks great overall.

@gabina gabina requested a review from ragesoss November 7, 2023 22:05
@ragesoss ragesoss merged commit c81359d into WikiEducationFoundation:master Nov 7, 2023
1 check passed
@gabina gabina deleted the Add-admin-view-to-copy-courses-from-production-instance-of-dashboard branch November 7, 2023 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a way for admins to copy courses from a production instance of the Dashboard
2 participants