Compare commits
22 Commits
feature/sa
...
c50098a55c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c50098a55c | ||
|
|
e73126bcb7 | ||
|
|
6c29d18696 | ||
|
|
3fbc019083 | ||
|
|
3086f78d34 | ||
|
|
d15fc918d1 | ||
|
|
56c0c3838d | ||
|
|
9ac69e30d0 | ||
|
|
d37183ba45 | ||
|
|
b4bdeeb9f6 | ||
|
|
f4143ab106 | ||
|
|
516e132611 | ||
|
|
c5305490c1 | ||
|
|
4520f94b69 | ||
|
|
e4f1ba96ad | ||
|
|
52c0849de2 | ||
|
|
b9fa3bd008 | ||
|
|
2bc672e4c5 | ||
|
|
962c84e6d2 | ||
|
|
fc1bec4de7 | ||
|
|
0275b96014 | ||
|
|
e4f3bad971 |
@@ -21,13 +21,13 @@ export class RecordShare extends BaseModel {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't auto-set timestamps - let DB defaults handle them
|
// Override BaseModel hooks to prevent automatic timestamp handling
|
||||||
$beforeInsert() {
|
$beforeInsert(queryContext: any) {
|
||||||
// Don't call super - skip BaseModel's timestamp logic
|
// Don't set timestamps - let database defaults handle it
|
||||||
}
|
}
|
||||||
|
|
||||||
$beforeUpdate() {
|
$beforeUpdate(opt: any, queryContext: any) {
|
||||||
// Don't call super - skip BaseModel's timestamp logic
|
// Don't set timestamps - let database defaults handle it
|
||||||
}
|
}
|
||||||
|
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|||||||
@@ -147,43 +147,39 @@ export class RecordSharingController {
|
|||||||
|
|
||||||
if (existingShare) {
|
if (existingShare) {
|
||||||
// Update existing share
|
// Update existing share
|
||||||
const updated = await RecordShare.query(knex)
|
await knex('record_shares')
|
||||||
.patchAndFetchById(existingShare.id, {
|
.where({ id: existingShare.id })
|
||||||
accessLevel: {
|
.update({
|
||||||
|
accessLevel: JSON.stringify({
|
||||||
canRead: data.canRead,
|
canRead: data.canRead,
|
||||||
canEdit: data.canEdit,
|
canEdit: data.canEdit,
|
||||||
canDelete: data.canDelete,
|
canDelete: data.canDelete,
|
||||||
},
|
}),
|
||||||
// Convert ISO string to MySQL datetime format
|
expiresAt: data.expiresAt ? data.expiresAt : null,
|
||||||
expiresAt: data.expiresAt
|
updatedAt: knex.fn.now(),
|
||||||
? knex.raw('?', [new Date(data.expiresAt).toISOString().slice(0, 19).replace('T', ' ')])
|
});
|
||||||
: null,
|
|
||||||
} as any);
|
|
||||||
|
|
||||||
return RecordShare.query(knex)
|
return RecordShare.query(knex)
|
||||||
.findById(updated.id)
|
.findById(existingShare.id)
|
||||||
.withGraphFetched('[granteeUser]');
|
.withGraphFetched('[granteeUser]');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new share
|
// Create new share
|
||||||
const share = await RecordShare.query(knex).insertAndFetch({
|
const [shareId] = await knex('record_shares').insert({
|
||||||
objectDefinitionId: objectDef.id,
|
objectDefinitionId: objectDef.id,
|
||||||
recordId,
|
recordId,
|
||||||
granteeUserId: data.granteeUserId,
|
granteeUserId: data.granteeUserId,
|
||||||
grantedByUserId: currentUser.userId,
|
grantedByUserId: currentUser.userId,
|
||||||
accessLevel: {
|
accessLevel: JSON.stringify({
|
||||||
canRead: data.canRead,
|
canRead: data.canRead,
|
||||||
canEdit: data.canEdit,
|
canEdit: data.canEdit,
|
||||||
canDelete: data.canDelete,
|
canDelete: data.canDelete,
|
||||||
},
|
}),
|
||||||
// Convert ISO string to MySQL datetime format: YYYY-MM-DD HH:MM:SS
|
expiresAt: data.expiresAt ? data.expiresAt : null,
|
||||||
expiresAt: data.expiresAt
|
});
|
||||||
? knex.raw('?', [new Date(data.expiresAt).toISOString().slice(0, 19).replace('T', ' ')])
|
|
||||||
: null,
|
|
||||||
} as any);
|
|
||||||
|
|
||||||
return RecordShare.query(knex)
|
return RecordShare.query(knex)
|
||||||
.findById(share.id)
|
.findById(shareId)
|
||||||
.withGraphFetched('[granteeUser]');
|
.withGraphFetched('[granteeUser]');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,9 +235,11 @@ export class RecordSharingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Revoke the share (soft delete)
|
// Revoke the share (soft delete)
|
||||||
await RecordShare.query(knex)
|
await knex('record_shares')
|
||||||
.patchAndFetchById(shareId, {
|
.where({ id: shareId })
|
||||||
revokedAt: knex.fn.now() as any,
|
.update({
|
||||||
|
revokedAt: knex.fn.now(),
|
||||||
|
updatedAt: knex.fn.now(),
|
||||||
});
|
});
|
||||||
|
|
||||||
return { success: true };
|
return { success: true };
|
||||||
|
|||||||
@@ -146,15 +146,14 @@
|
|||||||
|
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<Label for="expiresAt">Expires At (Optional)</Label>
|
<Label for="expiresAt">Expires At (Optional)</Label>
|
||||||
<div class="flex gap-2">
|
<Input
|
||||||
<DatePicker
|
id="expiresAt"
|
||||||
v-model="expiresDate"
|
v-model="newShare.expiresAt"
|
||||||
placeholder="Select date"
|
type="datetime-local"
|
||||||
class="flex-1"
|
placeholder="Never"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button variant="outline" @click="showShareDialog = false">Cancel</Button>
|
<Button variant="outline" @click="showShareDialog = false">Cancel</Button>
|
||||||
<Button
|
<Button
|
||||||
@@ -179,7 +178,6 @@ import { Input } from '~/components/ui/input';
|
|||||||
import { Label } from '~/components/ui/label';
|
import { Label } from '~/components/ui/label';
|
||||||
import { Badge } from '~/components/ui/badge';
|
import { Badge } from '~/components/ui/badge';
|
||||||
import Checkbox from '~/components/ui/checkbox.vue';
|
import Checkbox from '~/components/ui/checkbox.vue';
|
||||||
import DatePicker from '~/components/ui/date-picker/DatePicker.vue';
|
|
||||||
import { UserPlus, Trash2, Users } from 'lucide-vue-next';
|
import { UserPlus, Trash2, Users } from 'lucide-vue-next';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -208,24 +206,6 @@ const newShare = ref({
|
|||||||
expiresAt: '',
|
expiresAt: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const expiresDate = ref<Date | null>(null);
|
|
||||||
const expiresTime = ref('');
|
|
||||||
|
|
||||||
// Computed property to combine date and time into ISO string
|
|
||||||
const combinedExpiresAt = computed(() => {
|
|
||||||
if (!expiresDate.value) return '';
|
|
||||||
|
|
||||||
const date = new Date(expiresDate.value);
|
|
||||||
if (expiresTime.value) {
|
|
||||||
const [hours, minutes] = expiresTime.value.split(':');
|
|
||||||
date.setHours(parseInt(hours), parseInt(minutes), 0, 0);
|
|
||||||
} else {
|
|
||||||
date.setHours(23, 59, 59, 999); // Default to end of day
|
|
||||||
}
|
|
||||||
|
|
||||||
return date.toISOString();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Filter out users who already have shares
|
// Filter out users who already have shares
|
||||||
const availableUsers = computed(() => {
|
const availableUsers = computed(() => {
|
||||||
const sharedUserIds = new Set(shares.value.map(s => s.granteeUserId));
|
const sharedUserIds = new Set(shares.value.map(s => s.granteeUserId));
|
||||||
@@ -264,10 +244,6 @@ const loadUsers = async () => {
|
|||||||
const createShare = async () => {
|
const createShare = async () => {
|
||||||
try {
|
try {
|
||||||
sharing.value = true;
|
sharing.value = true;
|
||||||
|
|
||||||
const expiresAtValue = combinedExpiresAt.value;
|
|
||||||
console.log('Creating share, expiresAt value:', expiresAtValue);
|
|
||||||
|
|
||||||
const payload: any = {
|
const payload: any = {
|
||||||
granteeUserId: newShare.value.userId,
|
granteeUserId: newShare.value.userId,
|
||||||
canRead: newShare.value.canRead,
|
canRead: newShare.value.canRead,
|
||||||
@@ -276,15 +252,10 @@ const createShare = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Only include expiresAt if it has a value
|
// Only include expiresAt if it has a value
|
||||||
if (expiresAtValue) {
|
if (newShare.value.expiresAt && newShare.value.expiresAt.trim()) {
|
||||||
payload.expiresAt = expiresAtValue;
|
payload.expiresAt = newShare.value.expiresAt;
|
||||||
console.log('Including expiresAt in payload:', payload.expiresAt);
|
|
||||||
} else {
|
|
||||||
console.log('Skipping expiresAt - no date selected');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Final payload:', payload);
|
|
||||||
|
|
||||||
await api.post(
|
await api.post(
|
||||||
`/runtime/objects/${props.objectApiName}/records/${props.recordId}/shares`,
|
`/runtime/objects/${props.objectApiName}/records/${props.recordId}/shares`,
|
||||||
payload
|
payload
|
||||||
@@ -298,8 +269,6 @@ const createShare = async () => {
|
|||||||
canDelete: false,
|
canDelete: false,
|
||||||
expiresAt: '',
|
expiresAt: '',
|
||||||
};
|
};
|
||||||
expiresDate.value = null;
|
|
||||||
expiresTime.value = '';
|
|
||||||
await loadShares();
|
await loadShares();
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error('Failed to share record:', e);
|
console.error('Failed to share record:', e);
|
||||||
|
|||||||
Reference in New Issue
Block a user