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