Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict results for the /user route + Fix expiration_notif value #496

Merged
merged 9 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## 1.4.31 (Unreleased)

* Fix 'Admin' button in 'My projects' page for administrators
* Set expiration_notif = 0 when manually expiring a user
* Restrict '/user' route results when passing 'short=true' as a get param
* Add list of user DBs back to user page

## 1.4.30 (2024-08-02)

Expand Down
7 changes: 4 additions & 3 deletions manager2/src/app/admin/databases/databases.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ <h3>Declare existing database (no creation)</h3>
<input [ngModelOptions]="{standalone: true}" [(ngModel)]="db.host" id="dbhost" class="form-control" required>
</div>

<div class="col-sm-2">
<label><input type="checkbox" [ngModelOptions]="{standalone: true}" [(ngModel)]="db.single_user">Sole Owner</label>
<div class="col-sm-2 text-center">
<label for="sole" class="control-label">Sole owner</label>
<p><input style="transform: scale(1.5);" id="sole" type="checkbox" [ngModelOptions]="{standalone: true}" [(ngModel)]="db.single_user"></p>
</div>

<div class="col-sm-1">
<label style="opacity: 0;" class="control-label">Create</label>
<button type="button" class="p-button p-button-sm p-button-secondary" (click)="declare_db()">Declare DB</button>
<button type="button" class="p-button p-button-sm p-button-secondary" (click)="declare_db()">Declare</button>
</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion manager2/src/app/admin/projects/projects.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h3>Project creation</h3>
</select>
</div>
<div class="col-sm-1" *ngIf="!config.project || config.project.enable_group">
<label for="group_create">&nbsp;</label>
<label for="group_create" style="opacity: 0;">Create</label>
<button id="group_create" type="button" class="p-button button-primary" data-toggle="modal" data-target="#group_creation">
<span class="oi oi-plus" aria-hidden="true"></span>
</button>
Expand Down
27 changes: 24 additions & 3 deletions manager2/src/app/user/user.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h2>{{user.uid}}</h2>
</li>
</ul>
</div>

<div class="card-body">
<div class="row">
<div class="col-sm-6" *ngIf="panel == 0">
Expand Down Expand Up @@ -341,7 +341,7 @@ <h4>Update password</h4>
</form>
</div>
</div>

<div class="card bg-light" *ngIf="session_user.is_admin">
<div class="card-header">
<h4>Secondary groups</h4>
Expand Down Expand Up @@ -395,6 +395,27 @@ <h4>Projects</h4>
<app-user-projects [projects]="new_projects" [user_projects]="user_projects" [user]="user"></app-user-projects>
</div>
</div>

<div *ngIf="config.enable_ui && config.enable_ui.databases" class="card bg-light">
<div class="card-header">
<h4>Databases</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table aria-label="databases" *ngIf="databases && databases.length > 0" class="table table-striped">
<thead>
<th scope="col">Name</th>
</thead>
<tbody>
<tr *ngFor="let db of databases">
<td>{{db.name}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>

</div>

<div class="col-md-6 col-sm-12" *ngIf="panel == 1">
Expand Down Expand Up @@ -511,7 +532,7 @@ <h4>{{template.display_name}}</h4>
</div>
</div>
</div>

</div>
</div>

Expand Down
13 changes: 13 additions & 0 deletions manager2/src/app/user/user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { UserService } from './user.service'
import { AuthService } from '../auth/auth.service'
import { ConfigService } from '../config.service'
import { Website, WebsiteService } from './website.service'
import { Database, DatabaseService} from './database.service'
import { PluginService} from '../plugin/plugin.service'
import { GroupsService } from '../admin/groups/groups.service'
import { ProjectsService } from '../admin/projects/projects.service'
Expand Down Expand Up @@ -143,6 +144,8 @@ export class UserComponent implements OnInit {
website: Website
websites: Website[]

databases: Database[]

plugins: any[]
plugin_data: any

Expand Down Expand Up @@ -202,6 +205,7 @@ export class UserComponent implements OnInit {
private authService: AuthService,
private configService: ConfigService,
private websiteService: WebsiteService,
private databaseService: DatabaseService,
private pluginService: PluginService,
private groupService: GroupsService,
private projectService: ProjectsService,
Expand All @@ -217,6 +221,7 @@ export class UserComponent implements OnInit {
this.config = { }
this.website = new Website('', '', '', '')
this.websites = []
this.databases = []
this.plugins = []
this.plugin_data = { }
this.subscribed = false
Expand Down Expand Up @@ -404,6 +409,7 @@ export class UserComponent implements OnInit {
);
}
this.web_list();
this.db_list();

this.user.secondarygroups.sort(function (a,b) {
return a.localeCompare(b);
Expand Down Expand Up @@ -439,6 +445,13 @@ export class UserComponent implements OnInit {
);
}

db_list() {
this.databaseService.listOwner(this.user.uid).subscribe(
resp => this.databases = resp,
err => console.log('failed to get databases')
)
}

web_list() {
this.websiteService.listOwner(this.user.uid).subscribe(
resp => this.websites = resp,
Expand Down
2 changes: 1 addition & 1 deletion manager2/src/app/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export class UserService {
//}),
};
return this.http.get(
environment.apiUrl + '/user',
environment.apiUrl + '/user?short=true',
httpOptions).pipe(map((response: any[]) => {
return response.sort(function (a,b) {
return a.uid.localeCompare(b.uid);
Expand Down
8 changes: 2 additions & 6 deletions routes/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ router.put('/database/:id/owner/:old/:new', async function(req, res) {
res.status(401).send({ message: 'Not authorized' });
return;
}

await dbsrv.mongo_databases().updateOne({name: req.params.id}, {'$set': {owner: req.params.new}});
await dbsrv.mongo_events().insertOne({
'owner': session_user.uid,
Expand Down Expand Up @@ -282,18 +282,14 @@ router.post('/database/declare/:id', async function(req, res) {
res.status(401).send({ message: 'Only admins can declare a database' });
return;
}
if (!req.body.expire) {
res.status(403).send({ message: 'No expiration date' });
return;
}

let db = {
owner: req.body.owner ? req.body.owner : session_user.uid,
name: req.params.id,
type: req.body.type ? req.body.type : 'mysql',
host: req.body.host && sansrv.sanitize(req.body.host) ? req.body.host : CONFIG.mysql.host,
usage: req.body.usage ? req.body.usage : '',
size: req.body.size ? req.body.size : '',
expire: req.body.expire,
single_user: req.body.single_user !== undefined ? req.body.single_user : true
};
try {
Expand Down
13 changes: 11 additions & 2 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,16 @@ router.get('/user', async function(req, res) {
res.status(401).send({ message: 'Not authorized' });
return;
}
let users = await dbsrv.mongo_users().find({ }).toArray();

let users;

if (req.query.short === 'true') {
users = await dbsrv.mongo_users().find({ }).project({
history: 0,
}).toArray();
} else {
users = await dbsrv.mongo_users().find({ }).toArray();
}
res.json(users);
});

Expand Down Expand Up @@ -927,7 +936,7 @@ router.get('/user/:id/expire', async function(req, res) {
}
user.history.push({ 'action': 'expire', date: new Date().getTime() });
// eslint-disable-next-line no-unused-vars
await dbsrv.mongo_users().updateOne({ uid: user.uid },{ '$set': { status: STATUS_EXPIRED, expiration: new Date().getTime(), history: user.history } });
await dbsrv.mongo_users().updateOne({ uid: user.uid },{ '$set': { status: STATUS_EXPIRED, expiration: new Date().getTime(), history: user.history, expiration_notif: 0 } });

try {
let created_file = await filer.user_expire_user(user, fid);
Expand Down