mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-10 01:23:48 +01:00
Add admin action to warn about git/repo links instead of internal links
This commit is contained in:
parent
3ee4b723c1
commit
1b8c13914c
@ -29,6 +29,7 @@ from app.tasks.forumtasks import import_topic_list, check_all_forum_accounts
|
||||
from app.tasks.importtasks import import_repo_screenshot, check_zip_release, check_for_updates, update_all_game_support, \
|
||||
import_languages
|
||||
from app.tasks.usertasks import import_github_user_ids
|
||||
from app.tasks.pkgtasks import notify_about_git_forum_links
|
||||
from app.utils import add_notification, get_system_user
|
||||
|
||||
actions = {}
|
||||
@ -297,6 +298,13 @@ def do_import_github_user_ids():
|
||||
return redirect(url_for("tasks.check", id=task_id, r=url_for("admin.admin_page")))
|
||||
|
||||
|
||||
@action("Notify about links to git/forums instead of CDB")
|
||||
def do_notify_git_forums_links():
|
||||
task_id = uuid()
|
||||
notify_about_git_forum_links.apply_async((), task_id=task_id)
|
||||
return redirect(url_for("tasks.check", id=task_id, r=url_for("admin.admin_page")))
|
||||
|
||||
|
||||
@action("DANGER: Delete removed packages")
|
||||
def del_removed_packages():
|
||||
query = Package.query.filter_by(state=PackageState.DELETED)
|
||||
|
@ -14,9 +14,14 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import re
|
||||
|
||||
from app.models import Package, db
|
||||
from sqlalchemy import or_, and_
|
||||
|
||||
from app.models import Package, db, PackageState
|
||||
from app.tasks import celery
|
||||
from app.utils import post_bot_message
|
||||
|
||||
|
||||
@celery.task()
|
||||
def update_package_scores():
|
||||
@ -27,3 +32,48 @@ def update_package_scores():
|
||||
package.recalculate_score()
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def desc_contains(desc: str, search_str: str):
|
||||
if search_str.startswith("https://forum.minetest.net/viewtopic.php?%t="):
|
||||
reg = re.compile(search_str.replace(".", "\\.").replace("/", "\\/").replace("?", "\\?").replace("%", ".*"))
|
||||
return reg.search(desc)
|
||||
else:
|
||||
return search_str in desc
|
||||
|
||||
|
||||
@celery.task()
|
||||
def notify_about_git_forum_links():
|
||||
package_links = [(x[0], x[1]) for x in db.session.query(Package, Package.repo)
|
||||
.filter(Package.repo.is_not(None), Package.state == PackageState.APPROVED).all()]
|
||||
for pair in db.session.query(Package, Package.forums) \
|
||||
.filter(Package.forums.is_not(None), Package.state == PackageState.APPROVED).all():
|
||||
package_links.append((pair[0], f"https://forum.minetest.net/viewtopic.php?%t={pair[1]}"))
|
||||
|
||||
clauses = [and_(Package.id != pair[0].id, Package.desc.ilike(f"%{pair[1]}%")) for pair in package_links]
|
||||
packages = Package.query.filter(Package.desc != "", Package.desc.is_not(None), Package.state == PackageState.APPROVED, or_(*clauses)).all()
|
||||
|
||||
for package in packages:
|
||||
links = []
|
||||
|
||||
for (link_package, link) in package_links:
|
||||
if link_package != package and desc_contains(package.desc.lower(), link.lower()):
|
||||
links.append((link_package, link))
|
||||
|
||||
if len(links) > 0:
|
||||
msg = "There's a ContentDB dialog redesign coming to Minetest 5.9.0. " \
|
||||
"Clicking a ContentDB link stays inside Minetest but an external repository / forums " \
|
||||
"link will open a web browser.\n\nYou should also remove dependency lists, as CDB already shows that.\n"
|
||||
|
||||
for x in links:
|
||||
line = f"\n* {x[1]} -> {x[0].get_url('packages.view', absolute=True)}"
|
||||
line_added = msg + line
|
||||
if len(line_added) > 2000 - 150:
|
||||
post_bot_message(package, "You should link to ContentDB pages", msg)
|
||||
msg = f"(...continued)\n{line}"
|
||||
else:
|
||||
msg = line_added
|
||||
|
||||
post_bot_message(package, "You should link to ContentDB pages", msg)
|
||||
|
||||
db.session.commit()
|
||||
|
Loading…
Reference in New Issue
Block a user