introduce storagelimits

This commit is contained in:
Peter Hormanns 2021-08-16 18:38:31 +02:00
parent 885ece0522
commit 8c98a8feb6
4 changed files with 57 additions and 7 deletions

View File

@ -103,8 +103,10 @@ public class PacModuleImpl extends AbstractModuleImpl {
admin.setHomedir("/home/pacs/" + pac.getName()); admin.setHomedir("/home/pacs/" + pac.getName());
admin.setName(pac.getName()); admin.setName(pac.getName());
admin.setShell("/bin/bash"); admin.setShell("/bin/bash");
admin.setQuotaSoftlimit(0);
admin.setQuotaHardlimit(0); admin.setQuotaHardlimit(0);
admin.setQuotaSoftlimit(0);
admin.setStorageHardlimit(0);
admin.setStorageSoftlimit(0);
admin.setPac(pac); admin.setPac(pac);
long nUID = 20000; long nUID = 20000;
Long maxUid = (Long) em.createQuery("SELECT MAX(u.userId) FROM UnixUsers u").getSingleResult(); Long maxUid = (Long) em.createQuery("SELECT MAX(u.userId) FROM UnixUsers u").getSingleResult();

View File

@ -77,6 +77,14 @@ public class UnixUser extends AbstractEntity implements Serializable {
@Column(name = "quota_hardlimit", columnDefinition = "integer") @Column(name = "quota_hardlimit", columnDefinition = "integer")
private Integer quotaHardlimit; private Integer quotaHardlimit;
@AnnFieldIO(validation="[0-9]*", rw=ReadWriteAccess.READWRITE, overwriteName="storage_softlimit")
@Column(name = "storage_softlimit", columnDefinition = "integer")
private Integer storageSoftlimit;
@AnnFieldIO(validation="[0-9]*", rw=ReadWriteAccess.READWRITE, overwriteName="storage_hardlimit")
@Column(name = "storage_hardlimit", columnDefinition = "integer")
private Integer storageHardlimit;
public UnixUser() { public UnixUser() {
} }
@ -228,6 +236,22 @@ public class UnixUser extends AbstractEntity implements Serializable {
return quotaHardlimit; return quotaHardlimit;
} }
public Integer getStorageSoftlimit() {
return storageSoftlimit;
}
public void setStorageSoftlimit(Integer storage) {
this.storageSoftlimit = storage;
}
public void setStorageHardlimit(Integer storageLimit) {
this.storageHardlimit = storageLimit;
}
public Integer getStorageHardlimit() {
return storageHardlimit;
}
@Override @Override
public boolean isNew() { public boolean isNew() {
return id == 0; return id == 0;

View File

@ -208,6 +208,22 @@ public class UnixUserModuleImpl extends AbstractModuleImpl {
} }
} }
} }
if (detachedUnixUser.getStorageSoftlimit() != null) {
if (hasFullAccessOnPacOf(attachedUnixUser)) {
attachedUnixUser.setStorageSoftlimit(detachedUnixUser.getStorageSoftlimit());
if (detachedUnixUser.getStorageHardlimit() != null) {
attachedUnixUser.setStorageHardlimit(detachedUnixUser.getStorageHardlimit());
}
}
else {
Integer oldQuota = attachedUnixUser.getStorageSoftlimit();
Integer newQuota = detachedUnixUser.getStorageSoftlimit();
if (oldQuota != newQuota && !oldQuota.equals(newQuota)) {
throw new AuthorisationException(loginUser, "update", detachedUnixUser, "storage");
}
}
}
return super.update(attachedUnixUser); return super.update(attachedUnixUser);
} }

View File

@ -65,13 +65,21 @@ public class UnixUserRemote extends AbstractRemote {
if (assertNotNull(homedir)) { if (assertNotNull(homedir)) {
user.setHomedir(homedir); user.setHomedir(homedir);
} }
String quota = (String) map.get("quota_softlimit"); String quotaSoftlimit = (String) map.get("quota_softlimit");
if (assertNotNull(quota)) { if (assertNotNull(quotaSoftlimit)) {
user.setQuotaSoftlimit(Integer.parseInt(quota)); user.setQuotaSoftlimit(Integer.parseInt(quotaSoftlimit));
} }
String quotaLimit = (String) map.get("quota_hardlimit"); String quotaHardlimit = (String) map.get("quota_hardlimit");
if (assertNotNull(quotaLimit)) { if (assertNotNull(quotaHardlimit)) {
user.setQuotaHardlimit(Integer.parseInt(quotaLimit)); user.setQuotaHardlimit(Integer.parseInt(quotaHardlimit));
}
String storageSoftlimit = (String) map.get("storage_softlimit");
if (assertNotNull(storageSoftlimit)) {
user.setStorageSoftlimit(Integer.parseInt(storageSoftlimit));
}
String storageHardlimit = (String) map.get("storage_hardlimit");
if (assertNotNull(storageHardlimit)) {
user.setStorageHardlimit(Integer.parseInt(storageHardlimit));
} }
Boolean locked = (Boolean) map.get("locked"); Boolean locked = (Boolean) map.get("locked");
if (assertNotNull(locked)) { if (assertNotNull(locked)) {