Skip to content

Commit e5c6033

Browse files
rsiminelmboudet
andauthored
Extended projects (#612)
* add last_extended project attribute * implement last_extended * fix * Update CHANGELOG.md --------- Co-authored-by: mboudet <mateo.boudet@gmail.com>
1 parent 37e74b8 commit e5c6033

6 files changed

Lines changed: 20 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Ensure emails have name, destination and subject
66
* Fix bug in TP account deletion
7+
* Adds a 'last_extended' attribute to the Project type
78
* UI improvements on projects page
89
* Fix database creation validation confirmation email
910
* Fix database creation request email title

core/project.service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ exports.edit_project = edit_project;
2222
async function create_project(new_project, uuid, action_owner = 'auto') {
2323
logger.info('Create Project ' + new_project.id + ' uuid ' + uuid);
2424
new_project.created_at = new Date().getTime();
25+
new_project.last_extended = new_project.created_at;
2526
if (!new_project.expire) {
2627
new_project.expire = new Date().getTime() + CONFIG.project.default_expire * day_time;
2728
}

manager2/src/app/admin/project/project.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ export class ProjectComponent implements OnInit {
146146
}
147147

148148
update_project() {
149-
this.project.expire = new Date(this.project_expire).getTime();
149+
let new_expire = new Date(this.project_expire).getTime();
150+
if (new_expire != this.project.expire) {
151+
this.project.last_extended = new Date().getTime();
152+
this.project.expire = new_expire;
153+
}
150154
this.project.group = this.config.project.enable_group ? this.project.group : '';
151155
this.projectsService.update(this.project.id, this.project).subscribe(
152156
(resp) => {

manager2/src/app/admin/projects/projects.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ export class ProjectsComponent implements OnInit {
246246
if (!projects[i].created_at) {
247247
projects[i].created_at = parseInt(projects[i]['_id'].substring(0, 8), 16) * 1000;
248248
}
249+
if (!projects[i].last_extended) {
250+
projects[i].last_extended = projects[i].created_at;
251+
}
249252
}
250253
this.projects = active_projects;
251254
this.expired_projects = expired_projects;

manager2/src/app/admin/projects/projects.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class Project {
2727
path: string;
2828
expire: number;
2929
created_at: number;
30+
last_extended: number;
3031

3132
constructor(
3233
_id: string = '', uuid: string = '', id: string = '',
@@ -37,16 +38,16 @@ export class Project {
3738
low_cpu: number = null, high_cpu: number = null,
3839
orga: string = '', description: string = '',
3940
access: string = 'Group', path: string = '',
40-
expire: number = 0, created_at: number = null
41+
expire: number = 0, created_at: number = null,
42+
last_extended: number = null
4143
) {
4244
this._id = _id; this.uuid = uuid, this.id = id; this.owner = owner;
4345
this.managers = [...new Set([owner, ...managers])]; this.group = group; this.size = size;
4446
this.current_size = current_size; this.low_size = low_size; this.high_size = high_size;
4547
this.cpu = cpu; this.current_cpu = current_cpu; this.low_cpu = low_cpu; this.high_cpu = high_cpu;
4648
this.orga = orga; this.description = description; this.access = access; this.path = path;
47-
this.expire = expire; this.created_at = created_at;
49+
this.expire = expire; this.created_at = created_at; this.last_extended = last_extended;
4850
}
49-
5051
}
5152

5253
@Injectable({
@@ -70,7 +71,8 @@ export class ProjectsService {
7071
resp.orga || '', resp.description || '',
7172
resp.access || 'Group', resp.path || '',
7273
new Date(resp.expire).getTime() || 0,
73-
new Date(resp.created_at).getTime() || null
74+
new Date(resp.created_at).getTime() || null,
75+
new Date(resp.last_extended).getTime() || null
7476
);
7577
}
7678

routes/projects.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ router.post('/project/:id', async function (req, res) {
299299
size: req.body.size,
300300
cpu: req.body.cpu,
301301
expire: req.body.expire,
302+
last_extended: req.body.last_extended,
302303
description: req.body.description,
303304
access: req.body.access,
304305
orga: req.body.orga,
@@ -658,7 +659,9 @@ router.get('/project/:id/extend', async function (req, res) {
658659

659660
if (CONFIG.project && CONFIG.project.allow_extend) {
660661
let expiration = new Date().getTime() + 360 * 1000 * 60 * 60 * 24; // one year
661-
await dbsrv.mongo_projects().updateOne({ id: project.id }, { $set: { expire: expiration } });
662+
await dbsrv
663+
.mongo_projects()
664+
.updateOne({ id: project.id }, { $set: { expire: expiration, last_extended: new Date().getTime() } });
662665
return res.send({ message: 'validity period extended', expiration: expiration });
663666
}
664667
return;

0 commit comments

Comments
 (0)