load licences from server

This commit is contained in:
MiniDigger 2021-03-26 20:32:35 +01:00
parent 7548b0ca52
commit a096444336
2 changed files with 12 additions and 7 deletions

View File

@ -299,6 +299,7 @@ import { MemberList } from '~/components/projects';
@ProjectPermission(NamedPermission.EDIT_SUBJECT_SETTINGS)
export default class ProjectManagePage extends HangarProjectMixin {
roles!: Role[];
licences!: String[];
apiKey = '';
newName = '';
nameErrors: TranslateResult[] = [];
@ -357,11 +358,6 @@ export default class ProjectManagePage extends HangarProjectMixin {
return this.form.settings.license.type === '(custom)';
}
// TODO do we want to get those from the server? Jake: I think so, it'd be nice to admins to be able to configure default licenses, but not needed for MVP
get licences() {
return ['MIT', 'Apache 2.0', 'GPL', 'LGPL', '(custom)'];
}
onFileChange() {
if (this.projectIcon) {
const reader = new FileReader();
@ -475,8 +471,11 @@ export default class ProjectManagePage extends HangarProjectMixin {
generateApiKey() {}
async asyncData({ $api, $util }: Context) {
const roles = await $api.requestInternal('data/projectRoles', false).catch($util.handlePageRequestError);
return { roles };
const data = await Promise.all([$api.requestInternal('data/projectRoles', false), $api.requestInternal('data/licences', false)]).catch(
$util.handlePageRequestError
);
if (typeof data === 'undefined') return;
return { roles: data[0], licences: data[1] };
}
}
</script>

View File

@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.papermc.hangar.config.hangar.HangarConfig;
import io.papermc.hangar.model.Announcement;
import io.papermc.hangar.model.api.project.ProjectLicense;
import io.papermc.hangar.model.common.Color;
import io.papermc.hangar.model.common.NamedPermission;
import io.papermc.hangar.model.common.Platform;
@ -136,6 +137,11 @@ public class BackendDataController {
return ResponseEntity.ok(OrganizationRole.getAssignableRoles());
}
@GetMapping("/licences")
public ResponseEntity<List<String>> getLicences() {
return ResponseEntity.ok(config.getLicences());
}
@GetMapping("/validations")
public ResponseEntity<ObjectNode> getValidations() {
ObjectNode validations = mapper.createObjectNode();