]> source.dussan.org Git - archiva.git/commitdiff
Adding property edit
authorMartin Stockhammer <martin_s@apache.org>
Mon, 11 Jan 2021 22:38:14 +0000 (23:38 +0100)
committerMartin Stockhammer <martin_s@apache.org>
Mon, 11 Jan 2021 22:38:14 +0000 (23:38 +0100)
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java
archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.html
archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/modules/security/security-configuration/security-properties/security-properties.component.ts
archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/app/services/security.service.ts
archiva-modules/archiva-web/archiva-webapp/src/main/archiva-web/src/assets/i18n/en.json

index 947164934e4b8e687c32ef7b687255112621895b..341b6b7587899f5ef22e127b8ca9cc8a9d087343 100644 (file)
@@ -37,6 +37,7 @@ import org.apache.archiva.rest.api.model.v2.SecurityConfiguration;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
 
 import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -199,7 +200,6 @@ public interface SecurityConfigurationService
     Response updateConfigurationProperty( @PathParam ( "propertyName" )  String propertyName, PropertyEntry propertyValue)
         throws ArchivaRestServiceException;
 
-
     @Path("config/ldap")
     @GET
     @Produces({ APPLICATION_JSON })
index 59bcdefaf93c178b96e67effcadaa66097ca26f5..22acf8260171128a4fff20d87124df55eb952c0e 100644 (file)
             <tbody>
             <tr *ngFor="let propertyEntry  of propertyItem.data" >
                 <td>{{propertyEntry.key}}</td>
-                <td>{{propertyEntry.value}}</td>
+                <td *ngIf="isEdit(propertyEntry.key)"><input class="form-control" type="text" [(ngModel)]="propertyValue"></td>
+                <td *ngIf="!isEdit(propertyEntry.key)">{{propertyEntry.value}}</td>
                 <td>
-                    <a [routerLink]="['..','edit', propertyEntry.key]"
+                    <a [routerLink]="" (click)="toggleEditProperty(propertyEntry)"
                        [attr.title]="'security.config.properties.edit' |translate"><span class="fas fa-edit"></span></a>
-                    <a class="ml-2" [routerLink]="['..','delete', propertyEntry.key]"
-                       [attr.title]="'security.config.properties.delete' |translate"><span class="fas fa-trash-alt"></span></a>
                 </td>
             </tr>
             </tbody>
index 961866a18c665dbad87b485d46efea6baa2698e3..c714d5a7e641bc90706ca26c69dc3684b2ed83e7 100644 (file)
@@ -5,6 +5,8 @@ import {TranslateService} from "@ngx-translate/core";
 import {Observable} from "rxjs";
 import {PagedResult} from "@app/model/paged-result";
 import {SecurityService} from "@app/services/security.service";
+import {ToastService} from "@app/services/toast.service";
+import {ErrorResult} from "@app/model/error-result";
 
 @Component({
     selector: 'app-security-properties',
@@ -13,7 +15,10 @@ import {SecurityService} from "@app/services/security.service";
 })
 export class SecurityPropertiesComponent extends SortedTableComponent<PropertyEntry> implements OnInit {
 
-    constructor(translator: TranslateService, securityService: SecurityService) {
+    editProperty:string='';
+    propertyValue:string='';
+
+    constructor(translator: TranslateService, private securityService: SecurityService, private toastService: ToastService) {
         super(translator, function (searchTerm: string, offset: number, limit: number, orderBy: string[], order: string): Observable<PagedResult<PropertyEntry>> {
             // console.log("Retrieving data " + searchTerm + "," + offset + "," + limit + "," + orderBy + "," + order);
             return securityService.queryProperties(searchTerm, offset, limit, orderBy, order);
@@ -24,4 +29,31 @@ export class SecurityPropertiesComponent extends SortedTableComponent<PropertyEn
     ngOnInit(): void {
     }
 
+    isEdit(key:string) : boolean {
+        return this.editProperty == key;
+    }
+
+    updateProperty(key:string, value:string) {
+        console.log("Updating "+key+"="+value)
+        this.securityService.updateProperty(key, value).subscribe(
+            ()=>{
+                this.toastService.showSuccessByKey('security-properties', 'security.config.properties.edit_success')
+            },
+            (error: ErrorResult) => {
+                this.toastService.showErrorByKey('security-properties', 'security.config.properties.edit_failure', {error:error.firstMessageString()})
+            }
+        );
+    }
+
+    toggleEditProperty(propertyEntry:PropertyEntry) : void {
+        if (this.editProperty==propertyEntry.key) {
+            propertyEntry.value=this.propertyValue
+            this.editProperty='';
+            this.updateProperty(propertyEntry.key, this.propertyValue);
+            this.propertyValue = '';
+        } else {
+            this.editProperty = propertyEntry.key;
+            this.propertyValue = propertyEntry.value;
+        }
+    }
 }
index 8902341b13a5f4898fd152900bb1e264a32480d6..aef5127873f97492c4320b7b2d9a3b12876331a3 100644 (file)
@@ -116,4 +116,11 @@ export class SecurityService {
             }));
     }
 
+    updateProperty(propKey:string, propValue:string) : Observable<HttpResponse<any>> {
+      return this.rest.executeResponseCall('put', 'archiva','security/config/properties/'+encodeURI(propKey), {key:propKey, value:propValue})
+          .pipe(catchError((error: HttpErrorResponse) => {
+              return throwError(this.rest.getTranslatedErrorResult(error));
+          }))
+    }
+
 }
index 18074b7d47919d0d9ca495ae66ceff4779bc21ce..3e415b2ff7d56d3fc5b317b4380585a841300ebb 100644 (file)
         "attributes": {
           "key": "Key",
           "value": "Value"
-        }
+        },
+        "edit_success": "Property has been updated",
+        "edit_error": "Could not save the property value: {error}"
       }
     }
   },