[go: up one dir, main page]

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 page dedicated to page installs #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ router.use((req, res, next) => {
res.locals.navigation = [
{name: 'Users', path: '/admin/users'},
{name: 'Communities', path: '/admin/communities'},
{name: 'Installs', path: '/admin/installs'},
{name: 'Callbacks', path: '/callbacks'},
];
next();
Expand Down Expand Up @@ -68,6 +69,28 @@ router.route('/communities')
.catch(next),
);

router.route('/installs')
.get((req, res, next) => db.models.page
.findAll({order: [['id', 'ASC']]})
.then(pages => Promise.all(
pages.map(page =>
graph('community')
.qs({fields: 'id,install'})
.token(page.accessToken)
.send()
.then(response => {
page.permissions = response.install.permissions;
page.installType = response.install.install_type;
return page;
}),
)))
.then(pages => {
const state = crypto.randomBytes(12).toString('hex');
res.render('installs', {pages, state});
})
.catch(next),
);

router.route('/users')
.get((req, res, next) => db.models.user
.findAll({order: [['createdAt', 'DESC']], include: [{ model: db.models.community, as: 'community' }]})
Expand Down
28 changes: 19 additions & 9 deletions routes/loggedout.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,25 @@ router.route('/page_install')
.then(responses => {
const pageResponse = responses[0];
const communityResponse = responses[1];
return db.models.page.create({
id: pageResponse.id,
name: pageResponse.name,
accessToken: tokenResponse.access_token,
communityId: communityResponse.id,
communityName: communityResponse.name,
installId: communityResponse.install.id,
});
return db.models.page
.findById(pageResponse.id)
.then(page => {
if (page) {
return page.update({
name: pageResponse.name,
accessToken: tokenResponse.access_token,
});
} else {
return db.models.page.create({
id: pageResponse.id,
name: pageResponse.name,
accessToken: tokenResponse.access_token,
communityId: communityResponse.id,
communityName: communityResponse.name,
installId: communityResponse.install.id,
});
}
});
})}
)
.then(page => {
Expand All @@ -112,7 +123,6 @@ router.route('/community_install')
})
.send()
.then(tokenResponse => {
console.log(tokenResponse);
return graph('community')
.token(tokenResponse.access_token)
.qs({ fields: 'name' })
Expand Down
3 changes: 0 additions & 3 deletions static/js/pageInstallSuccess.js

This file was deleted.

32 changes: 0 additions & 32 deletions views/admin.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,6 @@ block content
p.
Various information about the current status of the application.

h2 Workplace Install (with full perms)
button(type="button", Install

h2 Workplace Install (with selected perms)
form(action="https://work.facebook.com/v3.2/dialog/work/app_install" method="get" 'wp', 'width=800,height=1000'); this.target = 'wp';")
input.form-control(type="hidden", name="app_id", value=329713124440482)
input.form-control(type="hidden", name="redirect_uri", value="https://scott-taaskly.herokuapp.com/page_install")
div.form-group
p Choose permissions required:
each val in ["link_unfurling", "bot_mention", "message", "read_user_email"]
div.checkbox-inline
input.checkbox-input(type='checkbox', name=`permissions[]`, value=val, id=`perm_${val}`)
label(for=`perm_${val}`)=val
div.form-group
label(for='suggested_page_name') Bot name:
input.form-control(type='text' id='suggested_page_name' placeholder='Bot name' name='suggested_page_name')
button(type="submit") Install

h2 Workplace Install Upgrade
form(action="https://work.mengk.sb.facebook.com/v3.2/dialog/work/app_upgrade" method="get" 'wp', 'width=800,height=1000'); this.target = 'wp';")
input.form-control(type="hidden", name="redirect_uri", value="https://scott-taaskly.herokuapp.com/page_install")
div.form-group
p Choose permissions required:
each val in ["link_unfurling", "bot_mention", "message", "read_user_email"]
div.checkbox-inline
input.checkbox-input(type='checkbox', name=`permissions[]`, value=val, id=`perm_${val}`)
label(for=`perm_${val}`)=val
div.form-group
label(for='install_id') Intall ID:
input.form-control(type='text' id='install_id' placeholder='123' name='install_id')
button(type="submit") Install

h2 Webhook Subscriptions
form(action="/admin/subscribe" method="post")
button(type="submit") Subscribe
Expand Down
48 changes: 48 additions & 0 deletions views/installs.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
extends layout

block content
h2 Install to Workplace
form(action="https://work.facebook.com/v3.2/dialog/work/app_install" method="get" 'wp', 'width=800,height=1000'); this.target = 'wp';")
input.form-control(type="hidden", name="app_id", value=`${process.env.APP_ID}`)
input.form-control(type="hidden", name="state", value=`${state}`)
input.form-control(type="hidden", name="redirect_uri", value=`${process.env.BASE_URL}/page_install`)
div.form-group
p Choose permissions required:
each val in ["link_unfurling", "bot_mention", "message", "read_user_email"]
div.checkbox-inline
input.checkbox-input(type='checkbox', name=`permissions[]`, value=val, id=`perm_${val}`)
label(for=`perm_${val}`)=val
div.form-group
label(for='suggested_page_name') Bot name:
input.form-control(type='text' id='suggested_page_name' placeholder='Bot name' name='suggested_page_name')
button(type="submit") Install

h2 All Installs
table.pages
thead
tr
th(style="width: 200px") Page ID
th Name
th Created Time
th Install Type
th Permissions
th Upgrade
tbody
each page in pages
tr
td= page.id
td= page.name
td= moment(page.createdAt).fromNow()
td= page.installType.toLowerCase()
td= page.permissions.join(', ').toLowerCase()
td
form(action="https://work.facebook.com/v3.2/dialog/work/app_upgrade" method="get" 'wp', 'width=800,height=1000'); this.target = 'wp';")
input.form-control(type="hidden", name="redirect_uri", value=`${process.env.BASE_URL}/page_install`)
input.form-control(type="hidden", name="install_id", value=`${page.installId}`)
div.form-group
p Choose permissions required:
each val in ["link_unfurling", "bot_mention", "message", "read_user_email"]
div.checkbox-inline
input.checkbox-input(type='checkbox', name=`permissions[]`, value=val, id=`perm_${val}_${page.id}`)
label(for=`perm_${val}_${page.id}`)=val
button(type="submit") Upgrade
10 changes: 8 additions & 2 deletions views/pageInstallSuccess.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ extends layout
block navigation

block content
script(src='/js/pageInstallSuccess.js')
script.
window. {
setTimeout(function(){
window.opener.location.reload();
self.close();
}, 3000);
};
h1 Community Installed
p.
Taaskly has been successfuly installed on the community #[strong= page.communityName] as #[strong = page.name].
Taaskly has been successfuly installed on the community #[strong= page.communityName] as #[strong= page.name].
if state
p The following state param has been passed:
pre= state
Expand Down