forked from kaverti/website
Friends (BETA)
This commit is contained in:
parent
bc62d8fbc4
commit
b99f9efaeb
|
@ -1,5 +1,82 @@
|
|||
<template>
|
||||
<main>
|
||||
|
||||
<div>
|
||||
<center>
|
||||
<h1>Privacy</h1>
|
||||
<br>
|
||||
<div>
|
||||
<h2>Team Wall opt out</h2>
|
||||
<b-switch
|
||||
type='is-info'
|
||||
v-model="privacy.wall"
|
||||
>
|
||||
Toggle
|
||||
</b-switch>
|
||||
</div>
|
||||
<br>
|
||||
<b-button
|
||||
class='button is-info'
|
||||
:loading='privacy.loading'
|
||||
@click='savePrivacy()'
|
||||
>
|
||||
Save privacy preferences
|
||||
</b-button>
|
||||
</center>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
<script>
|
||||
import FancyTextarea from '../FancyTextarea'
|
||||
|
||||
import AjaxErrorHandler from '../../assets/js/errorHandler'
|
||||
import logger from '../../assets/js/logger'
|
||||
|
||||
export default {
|
||||
name: 'settingsExperiments',
|
||||
components: {
|
||||
// eslint-disable-next-line vue/no-unused-components
|
||||
FancyTextarea
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
privacy: {
|
||||
wall: false,
|
||||
loading: false
|
||||
},
|
||||
}
|
||||
},
|
||||
computed: {},
|
||||
methods: {
|
||||
capitalizeFirstLetter(value) {
|
||||
return value.toUpperCase()
|
||||
},
|
||||
savePrivacy() {
|
||||
this.privacy.error = ''
|
||||
this.privacy.loading = true
|
||||
|
||||
this.axios
|
||||
.put(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'teams/admin/modify/' + this.$route.params.username, {
|
||||
userWallOptOut: this.privacy.wall
|
||||
})
|
||||
.then(() => {
|
||||
this.privacy.loading = false
|
||||
})
|
||||
.catch(e => {
|
||||
this.privacy.loading = false
|
||||
AjaxErrorHandler(this.$store)(e)
|
||||
})
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.axios.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'teams/view/' + this.$route.params.username)
|
||||
.then(res => {
|
||||
if (res.data.userWallOptOut) {
|
||||
this.privacy.wall = res.data.userWallOptOut || ''
|
||||
}
|
||||
})
|
||||
this.$store.dispatch('setTitle', 'Team Privacy')
|
||||
|
||||
logger('settingsGeneral')
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -141,9 +141,6 @@
|
|||
getUserInfo () {
|
||||
this.axios
|
||||
.get(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + `/` + `teams/view/${this.$route.params.username}`)
|
||||
.catch((e) => {
|
||||
AjaxErrorHandler(this.$store)(e)
|
||||
})
|
||||
},
|
||||
clearErrors () {
|
||||
this.errors.content = ''
|
||||
|
@ -187,8 +184,9 @@
|
|||
this.posts = res.data.teamWalls
|
||||
this.nextPostsCount = res.data.meta.postNumber
|
||||
})
|
||||
}).catch(() => {
|
||||
}).catch((e) => {
|
||||
this.loading = false
|
||||
AjaxErrorHandler(this.$store)(e)
|
||||
})
|
||||
},
|
||||
setFocusInput (val) {
|
||||
|
@ -216,9 +214,6 @@
|
|||
this.team = res.data
|
||||
this.nextPostsCount = res.data.meta.nextPostsCount
|
||||
})
|
||||
.catch((e) => {
|
||||
AjaxErrorHandler(this.$store)(e)
|
||||
})
|
||||
|
||||
logger('userWall', this.$route.params.username)
|
||||
},
|
||||
|
|
|
@ -186,8 +186,8 @@
|
|||
},
|
||||
doRelationship () {
|
||||
this.axios
|
||||
.put(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'relationships/' + this.user.username, {
|
||||
type: this.relationships.type
|
||||
.post(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'relationships/send', {
|
||||
friend: this.$route.params.username
|
||||
})
|
||||
.then(() => {
|
||||
this.description.loading = false
|
||||
|
|
|
@ -27,6 +27,14 @@ let Errors = {
|
|||
'We are no longer hiring moderators',
|
||||
400
|
||||
],
|
||||
teamPermissions: [
|
||||
'You do not have the required roles/permissions to perform this action.',
|
||||
401
|
||||
],
|
||||
friendRequestAlreadySent: [
|
||||
'You have already sent a friend request to this person, or you are currently friends.',
|
||||
400
|
||||
],
|
||||
teamDoesNotExist: [
|
||||
'This team does not exist.',
|
||||
400
|
||||
|
|
|
@ -5,8 +5,8 @@ module.exports = {
|
|||
'relationships',
|
||||
'type',
|
||||
{
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: "1",
|
||||
type: Sequelize.TEXT,
|
||||
defaultValue: "pending",
|
||||
allowNull: false
|
||||
},
|
||||
),
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module.exports = {
|
||||
up(queryInterface, Sequelize) {
|
||||
return Promise.all([
|
||||
queryInterface.addColumn(
|
||||
'relationships',
|
||||
'updatedAt',
|
||||
{
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
),
|
||||
queryInterface.addColumn(
|
||||
'relationships',
|
||||
'createdAt',
|
||||
{
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
),
|
||||
]);
|
||||
},
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
up: function(queryInterface, Sequelize) {
|
||||
return queryInterface.renameColumn('relationships', 'friend1', 'friend1Id');
|
||||
},
|
||||
|
||||
down: function(queryInterface, Sequelize) {
|
||||
//
|
||||
}
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
up: function(queryInterface, Sequelize) {
|
||||
return queryInterface.renameColumn('relationships', 'friend2', 'friend2Id');
|
||||
},
|
||||
|
||||
down: function(queryInterface, Sequelize) {
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
let createDOMPurify = require('dompurify');
|
||||
let { JSDOM } = require('jsdom');
|
||||
|
||||
let window = new JSDOM('').window;
|
||||
let DOMPurify = createDOMPurify(window);
|
||||
var escaped_str = require('querystring')
|
||||
const Errors = require('../lib/errors')
|
||||
let pagination = require('../lib/pagination.js')
|
||||
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
let Relationship = sequelize.define('Relationship', {
|
||||
type: {
|
||||
type: DataTypes.ENUM,
|
||||
defaultValue: "1",
|
||||
values: ['pending', 'accepted', 'ignored', 'pendingCanAccept'],
|
||||
validate: {
|
||||
isIn: {
|
||||
args: [['pending', 'accepted', 'ignored', 'pendingCanAccept']],
|
||||
msg: "Answer can only be one of the pre-defined options"
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
Relationship.associate = function (models) {
|
||||
Relationship.belongsTo(models.User, { as: 'friend1'})
|
||||
Relationship.belongsTo(models.User, { as: 'friend2'})
|
||||
}
|
||||
|
||||
return Relationship
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
let express = require('express')
|
||||
let router = express.Router()
|
||||
const auth = require('../lib/auth')
|
||||
const Errors = require('../lib/errors')
|
||||
let { User, Ban, Relationship } = require('../models')
|
||||
|
||||
router.post('/send', auth, async(req, res, next) => {
|
||||
try {
|
||||
if(req.body.friend !== undefined) {
|
||||
let queryObj = {
|
||||
where: {username: req.userData.username}
|
||||
}
|
||||
let user = await User.findOne(queryObj)
|
||||
let queryObj2 = {
|
||||
where: {username: req.body.friend}
|
||||
}
|
||||
let user2 = await User.findOne(queryObj2)
|
||||
if (!user) {
|
||||
throw Errors.unknown
|
||||
}
|
||||
if(!user2) {
|
||||
throw Errors.accountDoesNotExist
|
||||
}
|
||||
let checkIfSent = await Relationship.findOne({
|
||||
where: {friend1Id: user.id, friend2Id: user2.id}
|
||||
})
|
||||
if (checkIfSent) {
|
||||
throw Errors.friendRequestAlreadySent
|
||||
}
|
||||
Relationship.create({friend1Id: user.id, friend2Id: user2.id, type: 'pending'})
|
||||
Relationship.create({friend1Id: user2.id, friend2Id: user.id, type: 'pendingCanAccept'})
|
||||
res.status(200)
|
||||
res.json(user.toJSON())
|
||||
} else {
|
||||
res.status(400)
|
||||
res.json({success: false})
|
||||
}
|
||||
|
||||
} catch (err) { next(err) }
|
||||
})
|
||||
|
||||
router.get('/:username', auth, async(req, res, next) => {
|
||||
try {
|
||||
if(req.body.friend !== undefined) {
|
||||
let queryObj = {
|
||||
where: {username: req.userData.username}
|
||||
}
|
||||
let user = await User.findOne(queryObj)
|
||||
let queryObj2 = {
|
||||
where: {username: req.body.friend}
|
||||
}
|
||||
let user2 = await User.findOne(queryObj2)
|
||||
if (!user) {
|
||||
throw Errors.unknown
|
||||
}
|
||||
if(!user2) {
|
||||
throw Errors.accountDoesNotExist
|
||||
}
|
||||
let checkIfSent = await Relationship.findOne({
|
||||
where: {friend1Id: user.id, friend2Id: user2.id}
|
||||
})
|
||||
if (checkIfSent) {
|
||||
throw Errors.friendRequestAlreadySent
|
||||
}
|
||||
Relationship.create({friend1Id: user.id, friend2Id: user2.id, type: 'pending'})
|
||||
Relationship.create({friend1Id: user2.id, friend2Id: user.id, type: 'pendingCanAccept'})
|
||||
res.status(200)
|
||||
res.json(user.toJSON())
|
||||
} else {
|
||||
res.status(400)
|
||||
res.json({success: false})
|
||||
}
|
||||
|
||||
} catch (err) { next(err) }
|
||||
})
|
||||
module.exports = router
|
|
@ -152,8 +152,8 @@ router.get('/view/:username', async(req, res, next) => {
|
|||
if(user.banned) {
|
||||
throw Errors.teamBanned
|
||||
}
|
||||
if (user.userWallOptOut) {
|
||||
throw Errors.userWallOptOut
|
||||
if (user.teamWallOptOut) {
|
||||
res.json({teamWalls: []})
|
||||
}
|
||||
res.json(Object.assign(user.toJSON(limit)))
|
||||
} else {
|
||||
|
|
|
@ -227,8 +227,15 @@ router.put('/modify/:username', auth, async(req, res, next) => {
|
|||
console.log(user1.OwnerId, user2.id)
|
||||
if(otherThanNull) {
|
||||
if(req.autosan.body.description !== undefined, req.autosan.body.name !== undefined) {
|
||||
|
||||
let user = await Team.update({description: req.autosan.body.description, name: req.autosan.body.name}, {
|
||||
await Team.update({description: req.autosan.body.description, name: req.autosan.body.name}, {
|
||||
where: {
|
||||
username: req.params.username
|
||||
}
|
||||
})
|
||||
res.status(200)
|
||||
res.json({success: true})
|
||||
} else if(req.autosan.body.userWallOptOut !== undefined) {
|
||||
await Team.update({teamWallOptOut: req.autosan.body.userWallOptOut}, {
|
||||
where: {
|
||||
username: req.params.username
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ router.post('/post', postLimiter, auth, async(req, res, next) => {
|
|||
throw Errors.verifyEmail
|
||||
}
|
||||
|
||||
if(getWallUser.userWallOptOut) {
|
||||
if(getWallUser.teamWallOptOut) {
|
||||
throw Errors.userWallOptOut
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@ if(!config.maintenance) {
|
|||
app.use('/api/v1/marketplace', require('./routes/marketplace'))
|
||||
app.use('/api/v1/inventory', require('./routes/inventory'))
|
||||
app.use('/api/v1/transactions', require('./routes/transactions'))
|
||||
app.use('/api/v1/relationships', require('./routes/relationship'))
|
||||
app.use(require('./lib/errorHandler'))
|
||||
app.set('trust proxy', true)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue