Skip to content

Commit

Permalink
Refactor: User post on import endorsements
Browse files Browse the repository at this point in the history
  • Loading branch information
Etiene committed May 6, 2016
1 parent b220a1e commit 5240e5f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 59 deletions.
1 change: 0 additions & 1 deletion app.moon
Expand Up @@ -62,7 +62,6 @@ class MoonRocks extends lapis.Application
@include "applications.modules"
@include "applications.github"
@include "applications.admin"
@include "applications.toolbox"

@before_filter =>
@current_user = Users\read_session @
Expand Down
56 changes: 0 additions & 56 deletions applications/toolbox.moon

This file was deleted.

10 changes: 10 additions & 0 deletions applications/user.moon
Expand Up @@ -29,6 +29,10 @@ import
verify_return_to
from require "helpers.app"

import
transfer_endorsements
from require "helpers.toolbox"

import load_module, load_manifest from require "helpers.loaders"
import paginated_modules from require "helpers.modules"

Expand Down Expand Up @@ -159,6 +163,12 @@ class MoonRocksUser extends lapis.Application
@user = @current_user
@title = "Import Lua Toolbox - User Settings"
render: true

POST: =>
assert_csrf @
@transfer = true
@transfer_count = transfer_endorsements @
render: true
}

["user_settings.reset_password": "/settings/reset-password"]: ensure_https require_login respond_to {
Expand Down
26 changes: 26 additions & 0 deletions helpers/toolbox.moon
Expand Up @@ -5,12 +5,14 @@ db = require "lapis.db"
import
modules
labels
users
from require "secrets.toolbox"

import
Modules
Labels
LabelsModules
Followings
from require "models"


Expand All @@ -30,3 +32,27 @@ class Toolbox
label = Labels\find name: _labels[tonumber l]
if label
LabelsModules\create module_id: mod.id, label_id: label.id

transfer_endorsements: =>
transfer_count = 0
endorsements = {}

for u in *users
if u.email == @current_user.email
endorsements = u.endorsements

for e in *endorsements
name = _modules[tonumber e]
if name
m = Modules\find name: name
if m
follow = Followings\find source_user_id: @current_user.id, object_id: m.id
if not follow
Followings\create {
source_user_id: @current_user.id
object_type: Followings.object_types.module
object_id: m.id
}
transfer_count += 1

return transfer_count
6 changes: 4 additions & 2 deletions views/user_settings/import_toolbox.moon
Expand Up @@ -23,8 +23,10 @@ class UserSettingsImportToolbox extends require "widgets.user_settings_page"
p ->
test "No endorsements were imported."
else
p ->
a href: @url_for("transfer_endorses", account), "Transfer endorsements"
form action: @req.cmd_url, method: "POST", class: "form", ->
input type: "hidden", name: "csrf_token", value: @csrf_token
div class: "button_row", ->
input type: "submit", value: "Transfer endorsements"



Expand Down

0 comments on commit 5240e5f

Please sign in to comment.