Skip to content

Commit

Permalink
Merge pull request #543 from ever-co/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
evereq authored May 29, 2019
2 parents 505f8a6 + 11bccdb commit f5a8af1
Show file tree
Hide file tree
Showing 17 changed files with 225 additions and 12 deletions.
13 changes: 10 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ We would love for you to contribute to Ever Platform!

If you're changing the structure of the repository please create an issue first.

By default, when you submitting contributions with Pull Requests, we require electronic submission of individual [Contributor Assignment Agreement (CAA)](https://gist.github.com/evereq/95f74ae09510766ffa9379006715ccfd). In some cases (when contributions are very small, at our discretion) instead of CAA we may accept submission of individual [Contributor License Agreement (CLA)](https://gist.github.com/evereq/53ddec283243481344fb61df1706ec40).

If you submitting contribution on behalf of some legal entity, you need to submit Entity Contributor Assignment Agreement (CAA) or Entity Contributor License Agreement (CLA), which you can request by sending us an email to legal@ever.co.

We are using open-source [CLA assistant](https://github.com/cla-assistant/cla-assistant) project to collect your signatures on CAA.
The templates for our CAA/CLA documents generated by http://www.harmonyagreements.org.

## Submitting bug reports

Make sure you are on latest changes.
Expand All @@ -19,6 +26,6 @@ You are more than welcome to submit future requests here https://github.com/ever

This is an open source project.
Contributions you make to this public Ever Platform repository are completely voluntary.
When you submit an issue, bug report, question, enhancement, pull request, etc., you are offering your contribution without expectation of payment,
you expressly waive any future pay claims against the Ever Co. LTD related to your contribution, and you acknowledge that this does not create an obligation on the part of the Ever Co. LTD of any kind.
Furthermore, your contributing to this project does not create an employer-employee relationship between the Ever Co. LTD and the contributor.
When you submit an issue, bug report, question, enhancement, pull request, etc., you are offering your contribution without expectation of payment, you expressly waive any future pay claims against the Ever Co. LTD related to your contribution, and you acknowledge that this does not create an obligation on the part of the Ever Co. LTD of any kind. Furthermore, your contributing to this project does not create an employer-employee relationship between the Ever Co. LTD and the contributor.

See also "Submitting Pull Requests" section above for more information on CAA/CLA, required for any contributions.
36 changes: 36 additions & 0 deletions admin/website-angular/src/app/@core/data/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class UsersService {
email
apartment
phone
isBanned
geoLocation {
countryId
city
Expand Down Expand Up @@ -94,6 +95,7 @@ export class UsersService {
email
apartment
phone
isBanned
geoLocation {
streetAddress
city
Expand Down Expand Up @@ -145,6 +147,40 @@ export class UsersService {
return res.data['registerUser'];
}

async banUser(id: string) {
return this._apollo
.mutate({
mutation: gql`
mutation BanUser($id: String!) {
banUser(id: $id) {
id
firstName
lastName
}
}
`,
variables: { id }
})
.toPromise();
}

async unbanUser(id: string) {
return this._apollo
.mutate({
mutation: gql`
mutation UnbanUser($id: String!) {
unbanUser(id: $id) {
id
firstName
lastName
}
}
`,
variables: { id }
})
.toPromise();
}

async getCountOfUsers() {
const res = await this._apollo
.query({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="modal-header">
<h4 class="modal-title" id="modal-title">Profile Ban</h4>
<button
type="button"
class="close"
aria-label="Close button"
aria-describedby="modal-title"
(click)="modal.dismiss()"
>
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>
<strong
>Are you sure you want to {{ user.isBanned ? 'unban' : 'ban' }}
<span class="text-primary">"{{ user.name }}"</span>?</strong
>
</p>
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-outline-secondary"
(click)="modal.dismiss()"
>
Cancel
</button>
<button
type="button"
ngbAutofocus
class="btn btn-danger"
(click)="modal.close(user.id)"
>
Ok
</button>
</div>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit, Input } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { CustomerViewModel } from 'app/pages/+customers/customers.component';

@Component({
selector: 'ea-ban-confirm',
templateUrl: './ban-confirm.component.html',
styleUrls: ['./ban-confirm.component.scss']
})
export class BanConfirmComponent implements OnInit {
@Input() user: CustomerViewModel;
constructor(private readonly modal: NgbActiveModal) {}

ngOnInit() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BanConfirmComponent } from './ban-confirm.component';

@NgModule({
declarations: [BanConfirmComponent],
exports: [BanConfirmComponent],
entryComponents: [BanConfirmComponent],
imports: [CommonModule]
})
export class BanConfirmModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ban-confirm.module';
export * from './ban-confirm.component';
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@
<i class="ion-md-phone-portrait"></i>&nbsp;&nbsp;
{{ 'CUSTOMERS_VIEW.CUSTOMERS_DEVICES' | translate }}
</button>

<button
class="btn btn-danger mr-2 d-inline-block"
[disabled]="!isOnlyOneCustomerSelected"
(click)="banSelectedRows()"
>
<i class="ion-md-close-circle button-icon"></i>

<small _ngcontent-c55="" *ngIf="isUserBanned">{{
'CUSTOMERS_VIEW.UNBAN' | translate
}}</small>

<small _ngcontent-c55="" *ngIf="!isUserBanned">{{
'CUSTOMERS_VIEW.BAN' | translate
}}</small>
</button>
</nb-card-header>

<nb-card-body [nbSpinner]="loading">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { NotifyService } from '../../@core/services/notify/notify.service';
import { CustomerOrdersNumberComponent } from '../../@shared/render-component/customer-table/customer-orders-number/customer-orders-number.component';
import { CustomerEmailComponent } from '../../@shared/render-component/customer-email/customer-email.component';
import { CustomerPhoneComponent } from '../../@shared/render-component/customer-phone/customer-phone.component';
import { BanConfirmComponent } from 'app/@shared/user/ban-confirm';

export interface CustomerViewModel {
id: string;
Expand All @@ -32,6 +33,7 @@ export interface CustomerViewModel {
city: string;
address: string;
ordersQty: number;
isBanned: boolean;
}

const perPage = 7;
Expand Down Expand Up @@ -121,6 +123,40 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
}
}

protected banSelectedRows() {
if (this.isUserBanned) {
this.showUnbanPopup();
} else {
this.showBanPopup();
}
}

private showUnbanPopup() {
const modal = this._modalService.open(BanConfirmComponent, {
size: 'lg',
container: 'nb-layout',
windowClass: 'ng-custom',
backdrop: 'static'
});
modal.componentInstance.user = this._selectedCustomers[0];
modal.result
.then((id) => this._usersService.unbanUser(id))
.catch(console.error);
}

private showBanPopup() {
const modal = this._modalService.open(BanConfirmComponent, {
size: 'lg',
container: 'nb-layout',
windowClass: 'ng-custom',
backdrop: 'static'
});
modal.componentInstance.user = this._selectedCustomers[0];
modal.result
.then((id) => this._usersService.banUser(id))
.catch(console.error);
}

private _loadSettingsSmartTable() {
const columnTitlePrefix = 'CUSTOMERS_VIEW.SMART_TABLE_COLUMNS.';
const getTranslate = (name: string): Observable<any> =>
Expand Down Expand Up @@ -242,7 +278,8 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
address: `st. ${user.geoLocation.streetAddress ||
CustomersComponent.noInfoSign}, hse. № ${user
.geoLocation.house || CustomersComponent.noInfoSign}`,
ordersQty: userOrders ? userOrders.ordersCount : 0
ordersQty: userOrders ? userOrders.ordersCount : 0,
isBanned: user.isBanned
};
});

Expand All @@ -251,7 +288,6 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
const usersData = new Array(this.dataCount);

usersData.splice(perPage * (page - 1), perPage, ...usersVM);

await this.sourceSmartTable.load(usersData);
};

Expand Down Expand Up @@ -300,6 +336,16 @@ export class CustomersComponent implements AfterViewInit, OnDestroy {
this.dataCount = await this._usersService.getCountOfUsers();
}

public get isOnlyOneCustomerSelected(): boolean {
return this._selectedCustomers.length === 1;
}

public get isUserBanned() {
return (
this._selectedCustomers[0] && this._selectedCustomers[0].isBanned
);
}

ngOnDestroy() {
this.ngDestroy$.next();
this.ngDestroy$.complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { UserMutationModule } from '../../@shared/user/user-mutation';
import { CustomerTableModule } from '../../@shared/render-component/customer-table/customer-table.module';
import { NbSpinnerModule } from '@nebular/theme';
import { NotifyService } from 'app/@core/services/notify/notify.service';
import { BanConfirmModule } from 'app/@shared/user/ban-confirm';

const routes: Routes = [
{
Expand Down Expand Up @@ -41,7 +42,8 @@ const routes: Routes = [
RenderComponentsModule,
UserMutationModule,
CustomerTableModule,
NbSpinnerModule
NbSpinnerModule,
BanConfirmModule
],
declarations: [CustomersComponent],
providers: [JsonPipe, GeoLocationService, NotifyService]
Expand Down
2 changes: 2 additions & 0 deletions admin/website-angular/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@
"CREATE_CUSTOMER": "Create",
"DELETE": "DELETE",
"CREATE": "CREATE",
"BAN": "BAN",
"UNBAN": "UNBAN",
"MANAGE_CUSTOMER": "Manage customer",
"CUSTOMER": "Customer",
"CUSTOMERS_DEVICES": "Devices",
Expand Down
10 changes: 10 additions & 0 deletions backend/api/src/graphql/users/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,14 @@ export class UserResolver {
) {
return this._usersAuthService.addRegistrationInfo(id, registrationInfo);
}

@Mutation()
async banUser(_, { id }: { id: User['id'] }) {
return this._usersService.banUser(id);
}

@Mutation()
async unbanUser(_, { id }: { id: User['id'] }) {
return this._usersService.unbanUser(id);
}
}
6 changes: 6 additions & 0 deletions backend/api/src/graphql/users/users.types.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type User {
fullAddress: String

createdAt: Date

isBanned: Boolean!
}

input UserCreateInput {
Expand Down Expand Up @@ -147,4 +149,8 @@ type Mutation {
id: String!
registrationInfo: AdditionalUserRegistrationInfo!
): Void

banUser(id: String!): User

unbanUser(id: String!): User
}
10 changes: 10 additions & 0 deletions backend/api/src/services/users/UsersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,16 @@ export class UsersService extends DBService<User>
return this.Model.insertMany(customersToCreate);
}

async banUser(id: string): Promise<User> {
await this.throwIfNotExists(id);
return this.update(id, { isBanned: true });
}

async unbanUser(id: string): Promise<User> {
await this.throwIfNotExists(id);
return this.update(id, { isBanned: false });
}

/**
* Check if not deleted customer with given Id exists in DB and throw exception if it's not exists or deleted
*
Expand Down
10 changes: 10 additions & 0 deletions shared/core/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ class User extends DBObject<IUser, IUserCreateObject> implements IUser {
@Column()
isRegistrationCompleted: boolean;

/**
* Is customer banned
*
* @type {boolean}
* @memberof User
*/
@Types.Boolean(false)
@Column()
isBanned: boolean;

@Types.Boolean(false)
@Column()
isDeleted: boolean;
Expand Down
1 change: 1 addition & 0 deletions shared/core/interfaces/IUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface IUserInitializeObject extends DBCreateObject {
socialIds?: string[];
isRegistrationCompleted?: boolean;
hash?: string;
isBanned?: boolean;
}

export interface IUserCreateObject extends IUserInitializeObject {
Expand Down
Loading

0 comments on commit f5a8af1

Please sign in to comment.