🔐 Implement password and expiration date (#53)
* Implemented password and expiration date on conf and backend side * Implemented password modal on shared side * Add public link related tests * Fix tests
This commit is contained in:
@@ -78,6 +78,8 @@ export class DriveFile {
|
||||
export type AccessInformation = {
|
||||
public?: {
|
||||
token: string;
|
||||
password: string;
|
||||
expiration: number;
|
||||
level: publicAccessLevel;
|
||||
};
|
||||
entities: AuthEntity[];
|
||||
|
||||
@@ -386,6 +386,7 @@ export class DocumentsService {
|
||||
|
||||
return item;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
this.logger.error("Failed to update drive item", error);
|
||||
throw new CrudException("Failed to update item", 500);
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ export const getDefaultDriveItem = (
|
||||
],
|
||||
public: {
|
||||
level: "none",
|
||||
password: "",
|
||||
expiration: 0,
|
||||
token: generateAccessToken(),
|
||||
},
|
||||
},
|
||||
@@ -357,7 +359,7 @@ export const getAccessLevel = async (
|
||||
? "manage"
|
||||
: "write";
|
||||
|
||||
const publicToken = context.public_token;
|
||||
let publicToken = context.public_token;
|
||||
|
||||
try {
|
||||
item =
|
||||
@@ -379,7 +381,15 @@ export const getAccessLevel = async (
|
||||
//Public access
|
||||
if (publicToken) {
|
||||
if (!item.access_info.public.token) return "none";
|
||||
const { token: itemToken, level: itemLevel } = item.access_info.public;
|
||||
const { token: itemToken, level: itemLevel, password, expiration } = item.access_info.public;
|
||||
if (expiration && expiration < Date.now()) return "none";
|
||||
if (password) {
|
||||
const data = publicToken.split("+");
|
||||
if (data.length !== 2) return "none";
|
||||
const [extractedPublicToken, publicTokenPassword] = data;
|
||||
if (publicTokenPassword !== password) return "none";
|
||||
publicToken = extractedPublicToken;
|
||||
}
|
||||
if (itemToken === publicToken) return itemLevel;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ const documentSchema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
token: { type: "string" },
|
||||
password: { type: "string" },
|
||||
expiration: { type: "number" },
|
||||
level: { type: "string" },
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user