Files
wekan/models/listSyncCredentials.js
T
Lauri Ojansivu bb4a013939 Collection schemas share one createdAt and one modifiedAt autoValue.
34 schema files wrote the same two autoValue functions out by hand, 65
times in five spellings: createdAt set on insert and $setOnInsert on upsert,
unset otherwise; modifiedAt set on every write. They are now
createdAtAutoValue and modifiedAtAutoValue in models/lib/schemaTimestamps.js,
named by each field as `autoValue: createdAtAutoValue`. models/settings.js,
which may not use import statements, requires them.

Schemas whose rule differs keep their own: changeHistory keeps a createdAt
the caller set, and listSyncCredentials' updatedAt does not unset.

tests/schemaTimestamps runs both functions in SimpleSchema's insert, upsert,
update and validation contexts, and fails when a schema writes either one
out by hand again.

Thanks to xet7 !
2026-11-21 18:27:03 +02:00

59 lines
2.3 KiB
JavaScript

import { Mongo } from 'meteor/mongo';
import { createdAtAutoValue } from '/models/lib/schemaTimestamps';
const { SimpleSchema } = require('/imports/simpleSchema');
// Immutable credential versions, selected by Lists.syncRevision. A version
// is never active until settings and revision are committed in one list write.
// Older installations have an unversioned row keyed by listId.
//
// This collection is SERVER-ONLY on purpose: there is no Meteor.publish for
// it anywhere in the codebase (grep server/publications/ - it is not there),
// so a client subscription can never see a row of it, and no method returns
// a raw `token` value to the caller (server/listSync.js and the
// `listSync.setCredential`/`listSync.hasCredential` methods in
// server/methods/listSync.js are the only code that reads/writes it). This is
// the same "do not let a stored secret round-trip to the browser" rule the
// Admin Panel env-var/secrets work applies to server-only settings - applied
// here per-list instead of globally.
const ListSyncCredentials = new Mongo.Collection('listSyncCredentials');
ListSyncCredentials.attachSchema(
new SimpleSchema({
listId: {
type: String,
},
// Bind the saved credential to the exact provider/server/project tuple.
sourceKey: { type: String, optional: true },
// Server-selected account that authorized this immutable scheduled job.
runAsUserId: { type: String, optional: true },
incarnation: { type: String, optional: true },
configurationId: { type: String, optional: true },
generation: { type: Number, optional: true, min: 0, max: Number.MAX_SAFE_INTEGER },
// Free-form: a Jira API token, a GitHub/GitLab personal access token, a
// Gitea access token... whatever the source type's fetcher expects.
token: {
type: String,
},
// For Jira Cloud, Basic auth is "email:token" - the email half is not a
// secret, but it travels with the token so the fetcher has both without a
// second lookup.
username: {
type: String,
optional: true,
},
createdAt: {
type: Date,
autoValue: createdAtAutoValue,
},
updatedAt: {
type: Date,
optional: true,
autoValue() {
if (this.isUpdate || this.isUpsert || this.isInsert) return new Date();
},
},
}),
);
export default ListSyncCredentials;