Merge branch 'dev' into feat/um-62-prisma-property-names
commit
3143765954
|
|
@ -78,7 +78,8 @@ export default function WebsiteEditForm({ values, onSave, onClose }) {
|
||||||
const [message, setMessage] = useState();
|
const [message, setMessage] = useState();
|
||||||
|
|
||||||
const handleSubmit = async values => {
|
const handleSubmit = async values => {
|
||||||
const { websiteId } = values;
|
const { id: websiteId } = values;
|
||||||
|
|
||||||
const { ok, data } = await post(websiteId ? `/websites/${websiteId}` : '/websites', values);
|
const { ok, data } = await post(websiteId ? `/websites/${websiteId}` : '/websites', values);
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
|
|
@ -137,7 +138,6 @@ export default function WebsiteEditForm({ values, onSave, onClose }) {
|
||||||
defaultMessage="Enable share URL"
|
defaultMessage="Enable share URL"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
value={null}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ export function stringToColor(str) {
|
||||||
let color = '#';
|
let color = '#';
|
||||||
for (let i = 0; i < 3; i++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
let value = (hash >> (i * 8)) & 0xff;
|
let value = (hash >> (i * 8)) & 0xff;
|
||||||
color += ('00' + value.toString(16)).substring(-2);
|
color += ('00' + value.toString(16)).slice(-2);
|
||||||
}
|
}
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,7 @@ async function set(key, value) {
|
||||||
|
|
||||||
async function connect() {
|
async function connect() {
|
||||||
if (!redis) {
|
if (!redis) {
|
||||||
process.env.REDIS_URL && (global[REDIS] || getClient());
|
redis = process.env.REDIS_URL && (global[REDIS] || getClient());
|
||||||
|
|
||||||
if (!(await redis.get(INITIALIZED))) {
|
|
||||||
await stageData();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return redis;
|
return redis;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { getRandomChars, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
import { methodNotAllowed, ok, unauthorized, getRandomChars } from 'next-basics';
|
||||||
import { deleteWebsite, getWebsite, getWebsiteById, updateWebsite } from 'queries';
|
import { deleteWebsite, getAccount, getWebsite, updateWebsite } from 'queries';
|
||||||
import { allowQuery } from 'lib/auth';
|
import { allowQuery } from 'lib/auth';
|
||||||
import { useAuth, useCors } from 'lib/middleware';
|
import { useAuth, useCors } from 'lib/middleware';
|
||||||
import { validate } from 'uuid';
|
import { validate } from 'uuid';
|
||||||
|
|
@ -25,24 +25,31 @@ export default async (req, res) => {
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
await useAuth(req, res);
|
await useAuth(req, res);
|
||||||
|
|
||||||
const { isAdmin: currentUserIsAdmin, userId: currentUserId } = req.auth;
|
const { isAdmin: currentUserIsAdmin, userId: currentUserId, accountUuid } = req.auth;
|
||||||
const { name, domain, owner, enable_share_url } = req.body;
|
const { name, domain, owner, enable_share_url } = req.body;
|
||||||
|
let account;
|
||||||
|
|
||||||
const website = await getWebsiteById(websiteId);
|
if (accountUuid) {
|
||||||
|
account = await getAccount({ accountUuid });
|
||||||
|
}
|
||||||
|
|
||||||
|
const website = await getWebsite(where);
|
||||||
|
|
||||||
|
const shareId = enable_share_url ? website.shareId || getRandomChars(8) : null;
|
||||||
|
|
||||||
if (website.userId !== currentUserId && !currentUserIsAdmin) {
|
if (website.userId !== currentUserId && !currentUserIsAdmin) {
|
||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
let { shareId } = website;
|
await updateWebsite(
|
||||||
|
{
|
||||||
if (enable_share_url) {
|
name,
|
||||||
shareId = shareId ? shareId : getRandomChars(8);
|
domain,
|
||||||
} else {
|
shareId: shareId,
|
||||||
shareId = null;
|
userId: account ? account.id : +owner,
|
||||||
}
|
},
|
||||||
|
where,
|
||||||
await updateWebsite(websiteId, { name, domain, shareId, userId: +owner });
|
);
|
||||||
|
|
||||||
return ok(res);
|
return ok(res);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export default async (req, res) => {
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const { name, domain, owner, enable_share_url } = req.body;
|
const { name, domain, owner, enable_share_url } = req.body;
|
||||||
|
|
||||||
const website_owner = account ? account.userId : +owner;
|
const website_owner = account ? account.id : +owner;
|
||||||
|
|
||||||
if (website_owner !== currentUserId && !isAdmin) {
|
if (website_owner !== currentUserId && !isAdmin) {
|
||||||
return unauthorized(res);
|
return unauthorized(res);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export async function createWebsite(userId, data) {
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (redis.client && res) {
|
if (redis.client && res) {
|
||||||
await redis.client.set(`website:${res.websiteUuid}`, res.websiteId);
|
await redis.client.set(`website:${res.websiteUuid}`, res.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ export async function getWebsiteByUuid(websiteUuid) {
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (redis.client && res) {
|
if (redis.client && res) {
|
||||||
await redis.client.set(`website:${res.websiteUuid}`, res.websiteId);
|
await redis.client.set(`website:${res.websiteUuid}`, res.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
import prisma from 'lib/prisma';
|
import prisma from 'lib/prisma';
|
||||||
|
|
||||||
export async function updateWebsite(websiteId, data) {
|
export async function updateWebsite(data, where) {
|
||||||
return prisma.client.website.update({
|
return prisma.client.website.update({
|
||||||
where: {
|
where,
|
||||||
id: websiteId,
|
|
||||||
},
|
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ async function relationalQuery(websiteId, data) {
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
if (redis.client && res) {
|
if (redis.client && res) {
|
||||||
await redis.client.set(`session:${res.sessionUuid}`, res.sessionId);
|
await redis.client.set(`session:${res.sessionUuid}`, res.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue