Skip to content

Commit 48ea276

Browse files
Support for role config and operator info (#167)
* Use configuration for role names * Replace Owner by seller role * Configure certifier role * Fix issues with routes and role config * Use ID when quering offers by related party * Fix bug with wrong organization ID in the shopping cart * Fix bug reading the party when adding to the cart * Remove unused env import * Add link to the Profile section for accessing the payment system * ADD adhoc offer's form first approach (#150) * ADD first approach to custom offer form * ADD step validation and proper selection of parties * FIX ad hoc offer's form * Add button for downloading invoices * Allow to update the billNo in the CustomerBill * Remove hardcoding in orgAdmin roles --------- Co-authored-by: Lara Miñones <49403564+laraminones@users.noreply.github.com>
1 parent 15248a6 commit 48ea276

60 files changed

Lines changed: 1166 additions & 305 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cypress/e2e/catalog.cy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('/my-offerings',{
1616
const status = 'Active'
1717
const newCatalog = { id: 'test', href: 'test',name: name, description: description, lifecycleStatus: status, relatedParty: {
1818
id: local_items.partyId,
19-
role: 'Owner',
19+
role: 'Seller',
2020
'@referredType': ''
2121
}}
2222
let calls = 0
@@ -52,12 +52,12 @@ describe('/my-offerings',{
5252
const status = 'Active'
5353
const newCatalog = { id: 'test', href: 'test',name: name, description: description, lifecycleStatus: status, relatedParty: {
5454
id: local_items.partyId,
55-
role: 'Owner',
55+
role: 'Seller',
5656
'@referredType': ''
5757
}}
5858
const getCatalog = { id: 'test', href: 'test',name: check, description: description, lifecycleStatus: status, relatedParty: {
5959
id: local_items.partyId,
60-
role: 'Owner',
60+
role: 'Seller',
6161
'@referredType': ''
6262
}}
6363
let calls = 0

cypress/e2e/offering.cy.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('/my-offerings',{
2424

2525
const newCatalog = { id: 'test', href: 'test',name: 'catalogTest', description: '', lifecycleStatus: 'Launched', relatedParty: [{
2626
id: local_items.partyId,
27-
role: 'Owner',
27+
role: 'Seller',
2828
'@referredType': ''
2929
}]}
3030

@@ -75,7 +75,7 @@ describe('/my-offerings',{
7575

7676
const newCatalog = { id: 'catalogId', href: 'catalogId',name: 'catalogTest', description: '', lifecycleStatus: 'Launched', relatedParty: [{
7777
id: local_items.partyId,
78-
role: 'Owner',
78+
role: 'Seller',
7979
'@referredType': ''
8080
}]}
8181

@@ -154,7 +154,7 @@ describe('/my-offerings',{
154154

155155
const newCatalog = { id: 'catalogId', href: 'catalogId',name: 'catalogTest', description: '', lifecycleStatus: 'Launched', relatedParty: [{
156156
id: local_items.partyId,
157-
role: 'Owner',
157+
role: 'Seller',
158158
'@referredType': ''
159159
}]}
160160

@@ -168,7 +168,7 @@ describe('/my-offerings',{
168168
{
169169
"id": "mock:organization",
170170
"href": "mock:organization",
171-
"role": "owner",
171+
"role": "Seller",
172172
"@referredType": null
173173
}
174174
],
@@ -262,7 +262,7 @@ describe('/my-offerings',{
262262

263263
const newCatalog = { id: 'catalogId', href: 'catalogId',name: 'catalogTest', description: '', lifecycleStatus: 'Launched', relatedParty: [{
264264
id: local_items.partyId,
265-
role: 'Owner',
265+
role: 'Seller',
266266
'@referredType': ''
267267
}]}
268268

cypress/support/constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const catalog_launched = [
157157
{
158158
"id": "urn:ngsi-ld:individual:b73dd8ce-b63f-4c5b-be07-ca7ea10ad78e",
159159
"href": "urn:ngsi-ld:individual:b73dd8ce-b63f-4c5b-be07-ca7ea10ad78e",
160-
"role": "Owner",
160+
"role": "Seller",
161161
"@referredType": ""
162162
}
163163
],
@@ -313,7 +313,7 @@ export const productOffering = {
313313
{
314314
id: "urn:ngsi-ld:individual:56c77de4-f136-4167-95f0-92a36983ee0f",
315315
href: "urn:ngsi-ld:individual:56c77de4-f136-4167-95f0-92a36983ee0f",
316-
role: "Owner",
316+
role: "Seller",
317317
"@referredType": ""
318318
}
319319
]
@@ -331,7 +331,7 @@ export const productSpec = {
331331
{
332332
id: "urn:ngsi-ld:individual:56c77de4-f136-4167-95f0-92a36983ee0f",
333333
href: "urn:ngsi-ld:individual:56c77de4-f136-4167-95f0-92a36983ee0f",
334-
role: "Owner",
334+
role: "Seller",
335335
"@referredType": ""
336336
}
337337
],

src/app/app-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { UsageSpecsComponent } from "src/app/pages/usage-specs/usage-specs.compo
2323
import { DomeBlogComponent } from "src/app/pages/dome-blog/dome-blog.component"
2424
import { BlogEntryDetailComponent } from "src/app/pages/dome-blog/blog-entry-detail/blog-entry-detail.component"
2525
import { EntryFormComponent } from "src/app/pages/dome-blog/entry-form/entry-form.component"
26-
import { environment } from '../environments/environment';
26+
2727

2828

2929
const routes: Routes = [

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import { MultipleSelectComponent } from './shared/multiple-select/multiple-selec
8686
import {CharacteristicComponent} from "./shared/characteristic/characteristic.component";
8787
import {PricePlanDrawerComponent} from "./shared/price-plan-drawer/price-plan-drawer.component";
8888
import {OfferComponent} from "./shared/forms/offer/offer.component";
89+
import {CustomOfferComponent} from "./shared/forms/offer/custom-offer/custom-offer.component"
8990
import { ThemeService } from './services/theme.service';
9091
import { ThemeAwareTranslateLoader } from './services/theme-aware-translate.loader';
9192
import { RevenueReportComponent } from './shared/revenue-report/revenue-report.component'
@@ -196,6 +197,7 @@ import { OperatorRevenueSharingComponent } from "src/app/pages/admin/operator-re
196197
PricePlanDrawerComponent,
197198
RevenueReportComponent,
198199
OfferComponent,
200+
CustomOfferComponent,
199201
AboutDomeComponent,
200202
MarkdownTextareaComponent,
201203
ProviderRevenueSharingComponent,

src/app/chatbot-widget/chatbot-widget.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ export class ChatbotWidgetComponent {
6262

6363
// Build the message depending on the user role
6464
let name = "guest"
65-
let role = "Customer" // FIXME: Default role must be guest when supported
65+
let role = environment.BUYER_ROLE; // FIXME: Default role must be guest when supported
6666

6767
const userInfo = this.localStorage.getObject('login_items') as LoginInfo;
6868

6969
// The user is logged in
7070
if (userInfo.id) {
7171
let roles = []
72-
role = "Customer"
72+
role = environment.BUYER_ROLE;
7373
name = userInfo.username
7474

7575
if (userInfo.logged_as !== userInfo.id) {
@@ -83,7 +83,7 @@ export class ChatbotWidgetComponent {
8383
})
8484
}
8585

86-
if (roles.includes("seller")) {
86+
if (roles.includes(environment.SELLER_ROLE)) {
8787
role = "Provider"
8888
}
8989
}

src/app/features/quotes/services/quote.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ export class QuoteService {
172172
getQuotesByUserAndRole(userId: string, role: 'customer' | 'seller'): Observable<Quote[]> {
173173
let params = new HttpParams();
174174
// API expects 'Customer' or 'Seller' (capitalized)
175-
const apiRole = role === 'customer' ? 'Customer' : 'Seller';
175+
const apiRole = role === 'customer' ? environment.BUYER_ROLE : environment.SELLER_ROLE;
176176
params = params.set('role', apiRole);
177-
177+
178178
const encodedUserId = encodeURIComponent(userId);
179179
console.log('Getting quotes by user with URL:', `${this.apiUrl}/quoteByUser/${encodedUserId}`);
180180
return this.http.get<Quote[]>(`${this.apiUrl}/quoteByUser/${encodedUserId}`, { params, ...this.httpOptions });

src/app/guard/auth.guard.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {LocalStorageService} from "../services/local-storage.service";
44
import { Observable } from 'rxjs';
55
import { LoginInfo } from '../models/interfaces';
66
import * as moment from 'moment';
7+
import { environment } from 'src/environments/environment';
78

89
@Injectable({
910
providedIn: 'root',
@@ -18,21 +19,27 @@ export class AuthGuard implements CanActivate {
1819
): Observable<boolean> | Promise<boolean> | boolean {
1920
let aux = this.localStorage.getObject('login_items') as LoginInfo;
2021
const requiredRoles = route.data['roles'] as Array<string>;
21-
let userRoles: string | any[] = [];
22+
let userRoles: string[] = [];
23+
24+
const roleMapper:any = {
25+
'admin': environment.ADMIN_ROLE.toLowerCase(),
26+
'seller': environment.SELLER_ROLE.toLowerCase(),
27+
'buyer': environment.BUYER_ROLE.toLowerCase(),
28+
'orgAdmin': environment.ORG_ADMIN_ROLE.toLowerCase(),
29+
'certifier': environment.CERTIFIER_ROLE.toLowerCase(),
30+
'individual': 'individual'
31+
}
2232

2333
if(JSON.stringify(aux) != '{}' && (((aux.expire - moment().unix())-4) > 0)) {
2434
if(aux.logged_as == aux.id){
2535
userRoles.push('individual')
26-
for(let i=0; i < aux.roles.length; i++){
27-
userRoles.push(aux.roles[i].name)
28-
}
36+
aux.roles.forEach((role: any) => userRoles.push(role.name.toLowerCase()))
2937
} else {
3038
let loggedOrg = aux.organizations.find((element: { id: any; }) => element.id == aux.logged_as)
31-
for(let i=0;i<loggedOrg.roles.length;i++){
32-
userRoles.push(loggedOrg.roles[i].name)
33-
}
34-
if(aux.roles.some(role => role.name === 'admin')){
35-
userRoles.push('admin')
39+
loggedOrg.roles.forEach((role: any) => userRoles.push(role.name.toLowerCase()))
40+
41+
if(aux.roles.some(role => role.name.toLowerCase() === environment.ADMIN_ROLE.toLowerCase())){
42+
userRoles.push(environment.ADMIN_ROLE.toLowerCase())
3643
}
3744
}
3845
} else {
@@ -41,7 +48,9 @@ export class AuthGuard implements CanActivate {
4148
}
4249

4350
if (requiredRoles.length != 0) {
44-
const hasRequiredRoles = requiredRoles.some(role => userRoles.includes(role));
51+
const hasRequiredRoles = requiredRoles.some((role: any) => {
52+
return userRoles.includes(roleMapper[role]);
53+
});
4554

4655
if (!hasRequiredRoles) {
4756
this.router.navigate(['/dashboard']); // Navigate to an access denied page or login page

src/app/pages/checkout/checkout.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export class CheckoutComponent implements OnInit, OnDestroy {
268268
{
269269
id: this.relatedParty,
270270
href: this.relatedParty,
271-
role: 'Customer'
271+
role: environment.BUYER_ROLE
272272
}
273273
],
274274
priority: '4',
@@ -422,7 +422,7 @@ export class CheckoutComponent implements OnInit, OnDestroy {
422422

423423
groupItemsByOwner(ownerId: any) {
424424
const itemsForOwner = this.items.filter((item: any) => {
425-
const owner = item.relatedParty?.find((rp: any) => rp.role === 'Owner')?.id;
425+
const owner = item.relatedParty?.find((rp: any) => rp.role === environment.SELLER_ROLE)?.id;
426426
return owner === ownerId;
427427
});
428428

@@ -507,15 +507,20 @@ export class CheckoutComponent implements OnInit, OnDestroy {
507507
ba.selected = false;
508508
}
509509
this.selectedBillingAddress = baddr;
510+
console.log('billing addr selected....')
511+
console.log(this.selectedBillingAddress)
510512
const updatedItems = JSON.parse(JSON.stringify(this.items)); // we need a deep clone isntead of shallow clone
513+
511514
for (const cartItem of updatedItems){
515+
console.log('---- cart item ----')
516+
console.log(cartItem)
512517
const response = await lastValueFrom( this.priceService.calculatePrice({
513518
"productOrder":{
514519
"id": uuidv4(),
515520
"productOrderItem":[{
516521
action: "add",
517522
id: cartItem.id, // product offering id
518-
itemTotalPrice:[{
523+
itemTotalPrice: cartItem.options.pricing.length == 0 ? [] : [{
519524
productOfferingPrice:{
520525
id: cartItem.options.pricing[0].id, //product offering price parent id
521526
href: cartItem.options.pricing[0].id,

src/app/pages/product-details/product-details.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,10 +861,10 @@ async deleteProduct(product: Product | undefined){
861861
let parties = this.prodSpec?.relatedParty;
862862
if(parties)
863863
for(let i=0; i<parties.length;i++){
864-
if(parties[i].role=='Owner'){
864+
if(parties[i].role == environment.SELLER_ROLE){
865865
if(parties[i].id.includes('organization')){
866866
this.accService.getOrgInfo(parties[i].id).then(org => {
867-
this.orgInfo=org;
867+
this.orgInfo = org;
868868
console.log(this.orgInfo)
869869
})
870870
}

0 commit comments

Comments
 (0)