Skip to content

Commit

Permalink
Merge pull request #6966 from ever-co/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
evereq authored Oct 9, 2023
2 parents 6222c22 + 934c8ba commit 3c4d31b
Show file tree
Hide file tree
Showing 209 changed files with 1,205 additions and 901 deletions.
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@
"Desterrro",
"Chetan",
"chetan",
"Yostorono"
"Yostorono",
"sarif",
"SARIF"
],
"useGitignore": true,
"ignorePaths": [
Expand Down
4 changes: 2 additions & 2 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ CLIENT_BASE_URL=http://localhost:4200
#set to Website Platform
PLATFORM_WEBSITE_URL=https://gauzy.co

# DB_TYPE: sqlite | postgres
DB_TYPE=sqlite
# DB_TYPE: sqlite | postgres | better-sqlite3
DB_TYPE=better-sqlite3
DB_SYNCHRONIZE=false

# Below are PostgreSQL Connection Parameters
Expand Down
4 changes: 2 additions & 2 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ CLIENT_BASE_URL=http://localhost:4200
#set to Website Platform
PLATFORM_WEBSITE_URL=https://gauzy.co

# DB_TYPE: sqlite | postgres
DB_TYPE=sqlite
# DB_TYPE: sqlite | postgres | better-sqlite3
DB_TYPE=better-sqlite3
DB_SYNCHRONIZE=false

# Below are PostgreSQL Connection Parameters
Expand Down
4 changes: 2 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ CLIENT_BASE_URL=http://localhost:4200
#set to Website Platform
PLATFORM_WEBSITE_URL=https://gauzy.co

# DB_TYPE: sqlite | postgres
DB_TYPE=sqlite
# DB_TYPE: sqlite | postgres | better-sqlite3
DB_TYPE=better-sqlite3

# PostgreSQL Connection Parameters
# DB_HOST=localhost
Expand Down
21 changes: 21 additions & 0 deletions apps/api/src/plugin-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,26 @@ function getDbConfig(): DataSourceOptions {
logger: 'file', // Removes console logging, instead logs all queries in a file ormlogs.log
synchronize: process.env.DB_SYNCHRONIZE === 'true' ? true : false, // We are using migrations, synchronize should be set to false.
};
case 'better-sqlite3':
const betterSqlitePath =
process.env.DB_PATH ||
path.join(
path.resolve('.', ...['apps', 'api', 'data']),
'gauzy.sqlite3'
);

return {
type: dbType,
database: betterSqlitePath,
logging: 'all',
logger: 'file', // Removes console logging, instead logs all queries in a file ormlogs.log
synchronize: process.env.DB_SYNCHRONIZE === 'true', // We are using migrations, synchronize should be set to false.
prepareDatabase: (db) => {
if (!process.env.IS_ELECTRON) {
// Enhance performance
db.pragma('journal_mode = WAL');
}
}
};
}
}
45 changes: 6 additions & 39 deletions apps/desktop-timer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ app.on('ready', async () => {
if (!settings) {
launchAtStartup(true, false);
}
if (provider.dialect === 'sqlite') {
if (['sqlite', 'better-sqlite'].includes(provider.dialect)) {
try {
const res = await knex.raw(`pragma journal_mode = WAL;`);
console.log(res);
Expand Down Expand Up @@ -600,46 +600,13 @@ ipcMain.on('restart_and_update', () => {

ipcMain.on('check_database_connection', async (event, arg) => {
try {
const provider = arg.db;
let databaseOptions;
if (provider === 'postgres' || provider === 'mysql') {
databaseOptions = {
client: provider === 'postgres' ? 'pg' : 'mysql',
connection: {
host: arg[provider].dbHost,
user: arg[provider].dbUsername,
password: arg[provider].dbPassword,
database: arg[provider].dbName,
port: arg[provider].dbPort,
},
};
} else {
databaseOptions = {
client: 'sqlite3',
connection: {
filename: sqlite3filename,
},
};
}
const dbConn = require('knex')(databaseOptions);
await dbConn.raw('select 1+1 as result');
const driver = await provider.check(arg);
event.sender.send('database_status', {
status: true,
message:
provider === 'postgres'
? TranslateService.instant(
'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
{ driver: 'PostgresSQL' }
)
: provider === 'mysql'
? TranslateService.instant(
'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
{ driver: 'MySQL' }
)
: TranslateService.instant(
'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
{ driver: 'SQLite' }
),
message: TranslateService.instant(
'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
{ driver }
),
});
} catch (error) {
event.sender.send('database_status', {
Expand Down
33 changes: 7 additions & 26 deletions apps/desktop/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ async function startServer(value, restart = false) {
if (value.db === 'sqlite') {
process.env.DB_PATH = sqlite3filename;
process.env.DB_TYPE = 'sqlite';
} else {
}else if(value.db === 'better-sqlite') {
process.env.DB_PATH = sqlite3filename;
process.env.DB_TYPE = 'better-sqlite3';
}else {
process.env.DB_TYPE = 'postgres';
process.env.DB_HOST = value['postgres']?.dbHost;
process.env.DB_PORT = value['postgres']?.dbPort;
Expand Down Expand Up @@ -462,7 +465,7 @@ app.on('ready', async () => {
splashScreen = new SplashScreen(pathWindow.timeTrackerUi);
await splashScreen.loadURL();
splashScreen.show();
if (provider.dialect === 'sqlite') {
if (['sqlite', 'better-sqlite'].includes(provider.dialect)) {
try {
const res = await knex.raw(`pragma journal_mode = WAL;`)
console.log(res);
Expand Down Expand Up @@ -698,34 +701,12 @@ ipcMain.on('restart_and_update', () => {

ipcMain.on('check_database_connection', async (event, arg) => {
try {
const provider = arg.db;
let databaseOptions;
if (provider === 'postgres') {
databaseOptions = {
client: 'pg',
connection: {
host: arg[provider].dbHost,
user: arg[provider].dbUsername,
password: arg[provider].dbPassword,
database: arg[provider].dbName,
port: arg[provider].dbPort
}
};
} else {
databaseOptions = {
client: 'sqlite',
connection: {
filename: sqlite3filename,
},
};
}
const dbConn = require('knex')(databaseOptions);
await dbConn.raw('select 1+1 as result');
const driver = await provider.check(arg);
event.sender.send('database_status', {
status: true,
message: TranslateService.instant(
'TIMER_TRACKER.DIALOG.CONNECTION_DRIVER',
{ driver: provider === 'postgres' ? 'PostgresSQL' : 'SQLite' }
{ driver }
)
});
} catch (error) {
Expand Down
9 changes: 5 additions & 4 deletions apps/gauzy/src/app/@core/auth/auth-strategy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NbAuthResult, NbAuthStrategy } from '@nebular/auth';
import { ActivatedRoute } from '@angular/router';
import { catchError, filter, map, switchMap } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { IUser, IAuthResponse } from '@gauzy/contracts';
import { IUser, IAuthResponse, IUserLoginInput } from '@gauzy/contracts';
import { distinctUntilChange, isNotEmpty } from '@gauzy/common-angular';
import { NbAuthStrategyClass } from '@nebular/auth/auth.options';
import { AuthService } from '../services/auth.service';
Expand Down Expand Up @@ -102,7 +102,7 @@ export class AuthStrategy extends NbAuthStrategy {
rememberMe(data?: any) {
const rememberMe = !!data.rememberMe;
if (rememberMe) {
this.cookieService.set('email', data.email);
this.cookieService.set('email', data.email?.trim());
this.cookieService.set('rememberMe', 'true');
} else {
this.cookieService.delete('rememberMe');
Expand Down Expand Up @@ -130,7 +130,7 @@ export class AuthStrategy extends NbAuthStrategy {
lastName: fullName
? fullName.split(' ').slice(-1).join(' ')
: null,
email,
email: email?.trim(),
tenant,
tags,
},
Expand Down Expand Up @@ -296,7 +296,8 @@ export class AuthStrategy extends NbAuthStrategy {
}
}

public login(loginInput): Observable<NbAuthResult> {
public login(loginInput: IUserLoginInput): Observable<NbAuthResult> {
loginInput.email = loginInput.email?.trim();
return this.authService.login(loginInput).pipe(
map((res: IAuthResponse) => {
let user, token, refresh_token;
Expand Down
22 changes: 12 additions & 10 deletions apps/gauzy/src/app/@core/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import { API_PREFIX } from '../constants/app.constants';

@Injectable()
export class AuthService {

constructor(
private readonly http: HttpClient
) { }
constructor(private readonly http: HttpClient) {}

isAuthenticated(): Promise<boolean> {
return firstValueFrom(
Expand All @@ -33,7 +30,7 @@ export class AuthService {
return this.http.post<Object>(`${API_PREFIX}/auth/email/verify`, body);
}

login(loginInput): Observable<IAuthResponse> {
login(loginInput: IUserLoginInput): Observable<IAuthResponse> {
return this.http.post<IAuthResponse>(
`${API_PREFIX}/auth/login`,
loginInput
Expand All @@ -45,9 +42,14 @@ export class AuthService {
* @param input - IUserLoginInput containing email and password.
* @returns Promise<IUserSigninWorkspaceResponse> representing the response from the server.
*/
signinWorkspaces(input: IUserLoginInput): Observable<IUserSigninWorkspaceResponse> {
signinWorkspaces(
input: IUserLoginInput
): Observable<IUserSigninWorkspaceResponse> {
try {
return this.http.post<IUserSigninWorkspaceResponse>(`${API_PREFIX}/auth/signin.workspaces`, input);
return this.http.post<IUserSigninWorkspaceResponse>(
`${API_PREFIX}/auth/signin.workspaces`,
input
);
} catch (error) {
console.log('Error while signin workspaces: %s', error?.message);
// Handle errors appropriately (e.g., log, throw, etc.)
Expand Down Expand Up @@ -89,13 +91,13 @@ export class AuthService {

hasRole(roles: RolesEnum[]): Observable<boolean> {
return this.http.get<boolean>(`${API_PREFIX}/auth/role`, {
params: toParams({ roles })
params: toParams({ roles }),
});
}

hasPermissions(...permissions: PermissionsEnum[]): Observable<boolean> {
return this.http.get<boolean>(`${API_PREFIX}/auth/permissions`, {
params: toParams({ permissions })
params: toParams({ permissions }),
});
}

Expand All @@ -108,7 +110,7 @@ export class AuthService {
refreshToken(refresh_token: string): Promise<any> {
return firstValueFrom(
this.http.post<any>(`${API_PREFIX}/auth/refresh-token`, {
refresh_token: refresh_token
refresh_token: refresh_token,
})
);
}
Expand Down
4 changes: 3 additions & 1 deletion apps/gauzy/src/app/@shared/directives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OutsideDirective } from './outside.directive';
import { UnderConstructionDirective } from './under-construction.directive';
import { ReadMoreDirective } from './read-more';
import { TimeTrackingAuthorizedDirective } from './time-tracking-authorized-directive';
import { NoSpaceEdgesDirective } from './no-space-edges.directive';

export const DIRECTIVES = [
AutocompleteOffDirective,
Expand All @@ -13,5 +14,6 @@ export const DIRECTIVES = [
ReadMoreDirective,
TimeTrackingAuthorizedDirective,
OutsideDirective,
UnderConstructionDirective
UnderConstructionDirective,
NoSpaceEdgesDirective,
];
13 changes: 13 additions & 0 deletions apps/gauzy/src/app/@shared/directives/no-space-edges.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Directive, ElementRef, HostListener } from '@angular/core';

@Directive({
selector: '[noSpaceEdges]',
})
export class NoSpaceEdgesDirective {
constructor(private el: ElementRef) {}

@HostListener('input', ['$event.target.value'])
onInput(value: string) {
this.el.nativeElement.value = value.trim();
}
}
3 changes: 2 additions & 1 deletion apps/gauzy/src/app/@shared/regex/regex-patterns.const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const patterns = {
websiteUrl: /^((?:https?:\/\/)[^./]+(?:\.[^./]+)+(?:\/.*)?)$/,
imageUrl: /^(http)?s?:?(\/\/[^"']*\.(?:png|jpg|jpeg|gif|png|svg))/,
email: /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/,
host: /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/
host: /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/,
passwordNoSpaceEdges: /^(?!\s).*[^\s]$/,
};
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class DateRangePickerComponent extends TranslationBaseComponent implement
displayFormat: 'DD.MM.YYYY', // could be 'YYYY-MM-DDTHH:mm:ss.SSSSZ'
format: 'DD.MM.YYYY', // default is format value
direction: 'ltr',
firstDay: dayOfWeekAsString(this.store.selectedOrganization.startWeekOn) || moment.localeData().firstDayOfWeek()
firstDay: dayOfWeekAsString(this.store.selectedOrganization?.startWeekOn) || moment.localeData().firstDayOfWeek()
};
get locale(): LocaleConfig {
return this._locale;
Expand Down
5 changes: 5 additions & 0 deletions apps/gauzy/src/app/@theme/styles/_overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ body {
}

@mixin nb-overrides() {
p.caption.status-danger {
margin-bottom: 0;
margin-top: 0.3rem;
}

nb-route-tabset .route-tab.active .tab-link {
background: var(--gauzy-card-2);
margin-bottom: 1px;
Expand Down
12 changes: 7 additions & 5 deletions apps/gauzy/src/app/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { NgxResetPasswordComponent } from "./reset-password/reset-password.compo
import { NgxFaqModule } from '../@shared/faq';
import { ConfirmEmailModule } from './confirm-email';
import { ElectronService } from '../@core/auth/electron.service';
import { SharedModule } from '../@shared/shared.module';

@NgModule({
imports: [
Expand All @@ -48,10 +49,11 @@ import { ElectronService } from '../@core/auth/electron.service';
NbFormFieldModule,
NbSelectModule,
NbLayoutModule,
ThemeModule,
ThemeSelectorModule,
ThemeModule,
ThemeSelectorModule,
NgxFaqModule,
ConfirmEmailModule
ConfirmEmailModule,
SharedModule,
],
declarations: [
NgxLoginComponent,
Expand All @@ -61,8 +63,8 @@ import { ElectronService } from '../@core/auth/electron.service';
NgxRegisterSideSingleFeatureComponent,
NgxAuthComponent,
NgxRegisterComponent,
NgxResetPasswordComponent
NgxResetPasswordComponent,
],
providers: [ElectronService]
providers: [ElectronService],
})
export class NgxAuthModule {}
Loading

0 comments on commit 3c4d31b

Please sign in to comment.