Skip to content
Snippets Groups Projects
Commit b9ef80f2 authored by moon's avatar moon
Browse files

Merge branch 'approve' into develop

parents 8214a1ac e29e2faf
No related branches found
No related tags found
No related merge requests found
...@@ -25,5 +25,15 @@ module.exports = (plugin) => { ...@@ -25,5 +25,15 @@ module.exports = (plugin) => {
ctx.body = data; ctx.body = data;
}; };
plugin.controllers.user.find = async (ctx) => {
let data = await getService('user').fetchAll({}, ['role']);
if (data) {
data = await sanitizeOutput(data, ctx);
}
ctx.body = data;
};
return plugin; return plugin;
}; };
...@@ -60,28 +60,44 @@ export default { ...@@ -60,28 +60,44 @@ export default {
data: 'current_affiliation', data: 'current_affiliation',
}, },
{ {
title: 'Profile Link', title: 'Current Role/Link',
data: 'profile_link',
},
{
title: 'Current Role',
data: 'current_role', data: 'current_role',
fnCreatedCell: (nTd, sData, oData) => {
$(nTd).html(`${oData.current_role}<br><a class="extern-link" href="${oData.profile_link}">${oData.profile_link}</a>`);
},
}, },
{ {
title: 'Motivation', title: 'Role',
data: 'motivation_text', data: 'role.name',
}, },
{ {
title: 'Joined', title: 'Joined/Updated',
data: 'createdAt', data: 'createdAt',
fnCreatedCell: (nTd, sData, oData) => {
$(nTd).html(`${oData.createdAt.split('T')[0]} (J)<br>${oData.updatedAt.split('T')[0]} (U)`);
},
}, },
{ {
title: 'Updated', title: 'Confirmed',
data: 'updatedAt',
},
{
title: 'Status',
data: 'confirmed', data: 'confirmed',
fnCreatedCell: (nTd, sData, oData) => {
if(sData && oData.role.name === 'Authenticated') {
$(nTd).html(`<button class="rounded-md bg-transparent hover:bg-blue-500 text-blue-700
hover:text-white
border border-blue-500
hover:border-transparent
focus:ring-2 focus:ring-blue-300
items-center
px-4
py-2
text-center
edit-link">
Approve
</button>`);
} else {
$(nTd).html(`${sData}`);
}
},
}, },
]; ];
...@@ -120,12 +136,22 @@ export default { ...@@ -120,12 +136,22 @@ export default {
const row = table.row(tr); const row = table.row(tr);
vm.editUser(row.data().id); vm.editUser(row.data().id);
}); });
$(tableBody).on('click', 'tr td button.edit-link', (e) => {
e.preventDefault();
const tr = $(e.target).parent().parent();
const row = table.row(tr);
const dat = row.data();
vm.$emit('approve', dat)
});
}, },
}, },
}; };
</script> </script>
<style scoped> <style>
@import url("~@/assets/datatable.css"); @import url("~@/assets/datatable.css");
select.form-control { select.form-control {
...@@ -148,6 +174,11 @@ ul.pagination { ...@@ -148,6 +174,11 @@ ul.pagination {
color: #549bb0; color: #549bb0;
} }
.extern-link {
font-weight: bold;
color: #395384;
}
.pagination { .pagination {
font-size: 1.2rem; font-size: 1.2rem;
} }
......
...@@ -8,5 +8,8 @@ export const devApiHost = '/cms'; ...@@ -8,5 +8,8 @@ export const devApiHost = '/cms';
// export const apiHost = 'http://localhost:1337'; // export const apiHost = 'http://localhost:1337';
// export const devApiHost = 'http://localhost:1337'; // export const devApiHost = 'http://localhost:1337';
// apikey should be give here: // apikey should be given here:
export const apikey = process.env.VUE_APP_API_KEY; export const apikey = process.env.VUE_APP_API_KEY;
// wiki apikey should be given here:
export const wikiApikey = process.env.VUE_APP_WIKI_KEY;
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
size="lg" size="lg"
/> />
<h4>Profile update successful!</h4> <h4>{{toasterMessage}}</h4>
<button <button
class="btn btn-outline" class="btn btn-outline"
@click="hideDialog" @click="hideDialog"
...@@ -452,7 +452,7 @@ ...@@ -452,7 +452,7 @@
</template> </template>
</fetch-profile> </fetch-profile>
<fetch-users v-if="getRole === 'Administrator'"> <fetch-users v-if="getRole === 'Administrator'" :key="'users-' + updatedUsersKey">
<template slot-scope="{ response, loading }"> <template slot-scope="{ response, loading }">
<slot <slot
:response="response" :response="response"
...@@ -466,6 +466,7 @@ ...@@ -466,6 +466,7 @@
<user-table <user-table
id="usersTable" id="usersTable"
:data="response" :data="response"
@approve="approve"
/> />
</div> </div>
</slot> </slot>
...@@ -512,6 +513,7 @@ export default { ...@@ -512,6 +513,7 @@ export default {
isDev: process.env.NODE_ENV === 'development', isDev: process.env.NODE_ENV === 'development',
editMode: false, editMode: false,
toasterIsOpen: false, toasterIsOpen: false,
toasterMessage: 'Profile update successful!',
error: false, error: false,
scientificDisciplineOptions: [ scientificDisciplineOptions: [
{ id: '1', discipline: 'Physics' }, { id: '1', discipline: 'Physics' },
...@@ -530,6 +532,7 @@ export default { ...@@ -530,6 +532,7 @@ export default {
passwordErrMsg: '', passwordErrMsg: '',
errorMsg: '', errorMsg: '',
updatedKey: 0, updatedKey: 0,
updatedUsersKey: 0,
}; };
}, },
computed: { computed: {
...@@ -590,6 +593,7 @@ export default { ...@@ -590,6 +593,7 @@ export default {
this.showChangePassword = true; this.showChangePassword = true;
}, },
showDialog() { showDialog() {
this.toasterMessage = 'Profile update successful!';
this.toasterIsOpen = true; this.toasterIsOpen = true;
}, },
hideDialog() { hideDialog() {
...@@ -698,6 +702,7 @@ export default { ...@@ -698,6 +702,7 @@ export default {
// console.log(res.data); // console.log(res.data);
this.error = false; this.error = false;
this.toasterMessage = 'Profile update successful!';
this.toasterIsOpen = true; this.toasterIsOpen = true;
this.editMode = false; this.editMode = false;
this.isOpen = false; this.isOpen = false;
...@@ -715,6 +720,77 @@ export default { ...@@ -715,6 +720,77 @@ export default {
this.errorMsg = error; this.errorMsg = error;
} }
}, },
async approve(e) {
const vm = this
try {
vm.user = e.id;
if (vm.isDev) {
host = require('@/components/js/const').devApiHost;
}
let jwt = vm.jwt;
if (jwt === null) {
vm.loaded = false;
return;
}
const dat = {
id: vm.user,
role: 3, // Make the user contributor
};
let res = await this.axios.put(`${host}/api/users/${vm.user}`, dat, {
headers: {
Authorization: `Bearer ${jwt}`,
},
});
jwt = require('@/components/js/const').wikiApikey;
const query = `mutation User {
users {
create (email: "${e.email}",
name: "${e.full_name}",
passwordRaw: "welcome2cdcode",
providerKey: "local",
groups: 3,
mustChangePassword: true,
sendWelcomeEmail: true) {
responseResult {
succeeded,
errorCode,
slug,
message
},
user {
email,
name
}
}
}
}`
res = await this.axios.post(`https://wiki.cd-code.org/graphql`, { query }, {
headers: {
Authorization: `Bearer ${jwt}`,
},
});
vm.error = false;
vm.toasterMessage = 'Approved and a welcome email sent!';
vm.toasterIsOpen = true;
setTimeout(() => {
vm.toasterIsOpen = false;
}, 2000);
vm.updatedUsersKey += 1;
} catch (error) {
this.error = true;
this.errorMsg = error;
}
}
}, },
}; };
</script> </script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment