Miscellaneous

Assign multiple tasks per employee**.

1918

Back-end Changes

Find Users With Employee role.

  1. com.fastcode.timesheetapp1.restcontrollers.extended.UserControllerExtended.java.
@PreAuthorize("hasAnyAuthority('USERSENTITY_READ')")
    @RequestMapping(value= "/getEmployees", method = RequestMethod.GET, consumes = {"application/json"}, produces = {"application/json"})

  public ResponseEntity getEmployees(@RequestParam(value="search", required=false) String search, @RequestParam(value = "offset", required=false) String offset, @RequestParam(value = "limit", required=false) String limit, Sort sort) throws Exception
  1. com.fastcode.timesheetapp1.application.extended.Authorization.UserAppServiceExtended.java.
@Transactional(propagation = Propagation.NOT_SUPPORTED)
    
public List<FindUsersByIdOutput> findEmployees(String search, Pageable pageable) throws Exception
  1. com.fastcode.timesheetapp1.domain.extended.authorization.users.IUserRepositoryCustom.java.

This is a custom repository that was added to the generated application.

public interface IUserRepositoryCustom {
    Page<FindUsersByIdOutput> findEmployees(String search, Pageable pageable) throws Exception;
}
  1. com.fastcode.timesheetapp1.domain.extended.authorization.users.IUserRepositoryCustomImpl.java
// Get users with Employee role
public Page<FindUsersByIdOutput> findEmployees(String search, Pageable pageable) throws Exception

Front-end Changes

Update the new Usertask component to assign multiple tasks to an Employee at once in src/app/extended/entities/usertask/new/usertast-new.component.ts

  1. Add the following two methods:
  • selectAssociation (association: IAssociationEntry)
  • onSubmit()
  1. Add a method to fetch users with role Employee (ROLE_Employee) in src/app/extended/admin/user-management/users/user.service.ts**
  • public getEmployees(searchFields?: ISearchField[], offset?: number, limit?: number, sort?: string): Observable<IUsers[]>

Move entities menu item under administration

Front-end Changes

  1. Cut the following code from file src/app/extended/core/main-nav/main-nav.component.html.
<mat-expansion-panel class="expansion-panel" *ngIf="permissions['showEntities']">
          <mat-expansion-panel-header class="subnav-header">
            <i class="material-icons">
              dvr
              </i> &nbsp;{{'MainNav.Entities' | translate }}
          </mat-expansion-panel-header>
          <mat-nav-list class="subnav">
            <ng-container *ngFor="let entity of entityList">
              <a *ngIf="permissions[entity]" mat-list-item class="mat-sub-list-item" [class.active]="isActive(entity)" [routerLink]="[entity]">
               {{entity}}
              </a>
            </ng-container>
          </mat-nav-list>
       </mat-expansion-panel>
  1. Paste it under the administration admin panel (under the following source code section).
<mat-expansion-panel-header class="subnav-header">
  <i class="material-icons">
    account_box
  </i> &nbsp;{{'MainNav.Administration' | translate }}
</mat-expansion-panel-header>
  1. Create and assign a new permission for displaying entities under administration
  • Create a permission with the display name show entities and the name SHOW_ENTITIES to be assigned to the Admin role (ROLE_Admin)
  1. Make changes in src/app/extended/core/main-nav/main-nav.component.ts to add the permission in the permission map.
<mat-expansion-panel class="expansion-panel" 
        *ngIf="permissions['authEntities'] || permissions['showEntities'] || permissions['ENTITYHISTORY']">
        <mat-expansion-panel-header class="subnav-header">
          <i class="material-icons">
            account_box
            </i> &nbsp;{{'MainNav.Administration' | translate }}
        </mat-expansion-panel-header>

        <mat-expansion-panel class="expansion-panel" *ngIf="permissions['showEntities']">
          <mat-expansion-panel-header class="subnav-header">
            <i class="material-icons">
              dvr
              </i> &nbsp;{{'MainNav.Entities' | translate }}
          </mat-expansion-panel-header>
          <mat-nav-list class="subnav">
            <ng-container *ngFor="let entity of entityList">
              <a *ngIf="permissions[entity]" mat-list-item class="mat-sub-list-item" [class.active]="isActive(entity)" [routerLink]="[entity]">
               {{entity}}
              </a>
            </ng-container>
          </mat-nav-list>
       </mat-expansion-panel>

Check whether a Jwt token contains a specific permission.

Back-end Changes

  1. Add the method parseTokenAndCheckIfPermissionExists to the file
    com\fastcode\timesheetapp1\application\extended\authorization\users\UserAppServiceExtended.java
    .
public Boolean parseTokenAndCheckIfPermissionExists(String token, String permission)
    {
        SecurityContext securityContext = SecurityContextHolder.getContext();
        Authentication auth = securityContext.getAuthentication();
        return auth.getAuthorities().contains(new SimpleGrantedAuthority(permission));

    }

Add the permission SWAGGER_API

Front-end Changes

  1. Add "*ngIf="permissions['SWAGGER_API']"" in link in src/app/extended/core/main-nav/main-nav.component.html
<a mat-list-item class="sidenav-list-item" routerLink="swagger-ui" *ngIf="permissions['SWAGGER_API']">
   <i class="material-icons"> settings </i> &nbsp;{{ 'MainNav.API' | translate }}
</a>
  1. Add SWAGGER_API permission in perm array in setPermission method in the file src/app/extended/core/main-nav/main-nav.component.ts.
setPermissions() {
        …….
        let perms = ["SWAGGER_API"]
}