mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-10-19 22:27:20 +02:00
fix: distinguish repository publication and settings dates
This commit is contained in:
1 parent
22096a8346
commit
7cdf0f5e8d
12 files changed
+167
-21
No files matched your search
@@ -475,6 +475,8 @@ export default class Repository {
|
||||
if (status !== RepositoryStatus.ARCHIVED) this.assertNotArchived();
|
||||
if (!status) return this.model;
|
||||
const statusDate = new Date();
|
||||
const publishedAt = status === RepositoryStatus.READY && this.status !== RepositoryStatus.READY
|
||||
? statusDate : undefined;
|
||||
if (isConnected) {
|
||||
const result = await AnonymizedRepositoryModel.updateOne(
|
||||
{
|
||||
@@ -486,12 +488,13 @@ export default class Repository {
|
||||
"githubAccess.revision": this._model.githubAccess?.revision || { $exists: false },
|
||||
} : {}),
|
||||
},
|
||||
{ $set: { status, statusDate, statusMessage } }
|
||||
{ $set: { status, statusDate, statusMessage, ...(publishedAt ? { publishedAt } : {}) } }
|
||||
).exec();
|
||||
if (this.protectLifecycle && result.matchedCount === 0) {
|
||||
throw new AnonymousError("repository_job_cancelled", { httpStatus: 410 });
|
||||
}
|
||||
}
|
||||
if (publishedAt) this._model.publishedAt = publishedAt;
|
||||
this._model.status = status;
|
||||
this._model.statusDate = statusDate;
|
||||
this._model.statusMessage = statusMessage;
|
||||
|
||||
@@ -16,6 +16,8 @@ const AnonymizedRepositorySchema = new Schema({
|
||||
archiveCachePending: Boolean,
|
||||
statusMessage: String,
|
||||
anonymizeDate: Date,
|
||||
settingsSavedAt: Date,
|
||||
publishedAt: Date,
|
||||
lastView: Date,
|
||||
pageView: Number,
|
||||
accessToken: { type: String, select: false },
|
||||
|
||||
@@ -11,6 +11,8 @@ export interface IAnonymizedRepository {
|
||||
archiveReason?: string;
|
||||
archiveCachePending?: boolean;
|
||||
anonymizeDate: Date;
|
||||
settingsSavedAt?: Date;
|
||||
publishedAt?: Date;
|
||||
source: {
|
||||
type: "GitHubDownload" | "GitHubStream" | "Zip";
|
||||
branch?: string;
|
||||
|
||||
@@ -173,8 +173,10 @@ router.post(
|
||||
const reactivating = repo.status === RepositoryStatus.EXPIRED;
|
||||
const updates: Record<string, Date> = {
|
||||
"options.expirationDate": newExpiration,
|
||||
settingsSavedAt: new Date(),
|
||||
};
|
||||
repo.model.options.expirationDate = newExpiration;
|
||||
repo.model.settingsSavedAt = updates.settingsSavedAt;
|
||||
if (reactivating) {
|
||||
repo.model.anonymizeDate = new Date();
|
||||
updates.anonymizeDate = repo.model.anonymizeDate;
|
||||
@@ -572,6 +574,7 @@ router.post(
|
||||
{ _id: repo.model._id, "githubAccess.revision": previousAccessRevision || { $exists: false } },
|
||||
{
|
||||
$set: {
|
||||
settingsSavedAt: new Date(),
|
||||
options: repo.model.options,
|
||||
source: repo.model.source,
|
||||
githubAccess: repo.model.githubAccess,
|
||||
@@ -647,6 +650,7 @@ router.post("/", async (req, res) => {
|
||||
const repo = new AnonymizedRepositoryModel();
|
||||
repo.repoId = repoUpdate.repoId;
|
||||
repo.anonymizeDate = new Date();
|
||||
repo.settingsSavedAt = repo.anonymizeDate;
|
||||
repo.owner = user.id;
|
||||
repo.githubAccess = selectedAccess.binding;
|
||||
|
||||
|
||||
@@ -385,9 +385,15 @@ router.get(
|
||||
res.json({
|
||||
url: redirectURL,
|
||||
download: download || user?.isAdmin === true,
|
||||
lastUpdateDate: repo.model.source.commitDate
|
||||
? repo.model.source.commitDate
|
||||
: repo.model.anonymizeDate,
|
||||
// Source commits can predate publication by months and do not record
|
||||
// changes to anonymization settings or expiration.
|
||||
lastUpdateDate: new Date(Math.max(...[
|
||||
repo.model.anonymizeDate, repo.model.settingsSavedAt, repo.model.publishedAt,
|
||||
].filter((date): date is Date => !!date).map(date => new Date(date).getTime()))),
|
||||
anonymizedAt: repo.model.anonymizeDate,
|
||||
sourceCommitDate: repo.model.source.commitDate,
|
||||
settingsSavedAt: repo.model.settingsSavedAt,
|
||||
publishedAt: repo.model.publishedAt,
|
||||
isAdmin: user?.isAdmin === true,
|
||||
isOwner: user?.id == repo.model.owner,
|
||||
hasWebsite: !!repo.options.page && !!repo.options.pageSource,
|
||||
|
||||
Reference in new issue
Block a user