Skip to content

Commit

Permalink
permissions, tvorenie permissions, formulár pre role
Browse files Browse the repository at this point in the history
  • Loading branch information
rindo789 committed Oct 24, 2024
1 parent 9008241 commit 3dab28a
Show file tree
Hide file tree
Showing 22 changed files with 593 additions and 22 deletions.
151 changes: 151 additions & 0 deletions src/priv/Components/Modules/Core/Settings/FormUserRoles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import React, { Component } from 'react';
import { deepObjectMerge, getUrlParam } from 'adios/Helper';
import Form, { FormProps, FormState } from 'adios/Form';
import InputTags2 from 'adios/Inputs/Tags2';
import InputTable from 'adios/Inputs/Table';
import FormInput from 'adios/FormInput';
import TableRolePermissions from './TableRolePermissions';

interface FormUserRolesProps extends FormProps {}

interface FormUserRolesState extends FormState {}

export default class FormUserRoles<P, S> extends Form<FormUserRolesProps,FormUserRolesState> {
static defaultProps: any = {
...Form.defaultProps,
model: 'CeremonyCrmApp/Modules/Core/Settings/Models/UserRoles',
};

props: FormUserRolesProps;
state: FormUserRolesState;

constructor(props: FormUserRolesProps) {
super(props);
this.state = this.getStateFromProps(props);
}

getStateFromProps(props: FormUserRolesProps) {
return {
...super.getStateFromProps(props),
};
}

/* normalizeRecord(record) {
return record;
} */

renderHeaderLeft(): JSX.Element {
return <>
{this.state.isInlineEditing ? this.renderSaveButton() : this.renderEditButton()}
</>;
}

renderHeaderRight(): JSX.Element {
return <>
{this.state.isInlineEditing ? this.renderDeleteButton() : null}
{this.props.showInModal ? this.renderCloseButton() : null}
</>;
}

renderTitle(): JSX.Element {
if (getUrlParam('recordId') == -1) {
return(
<>
<h2>
{'New User Rolee'}
</h2>
</>
);
} else {
return (
<>
<h2>
{this.state.record.role
? this.state.record.role
: '[Undefined Name]'}
</h2>
</>
);
}
}

/* onBeforeSaveRecord(record: any) {
return record;
} */

renderContent(): JSX.Element {
const R = this.state.record;
const showAdditional = R.id > 0 ? true : false;

return (
<>
<div className='grid grid-cols-2 gap-1' style=
{{gridTemplateAreas:`
'info info'
'permissions permissions'
`}}>
<div className='card mt-4' style={{gridArea: 'info'}}>
<div className='card-body'>
{this.inputWrapper('role')}
</div>
</div>

<div className='card mt-4' style={{gridArea: 'permissions'}}>
<div className='card-header'>Permissions</div>
<div className='card-body'>
<InputTable
uid={this.props.uid + '_table_permissions_steps_input'}
{...this.getDefaultInputProps()}
value={R.PERMISSIONS}
onChange={(value: any) => {
this.updateRecord({ PERMISSIONS: value });
}}
>
<TableRolePermissions
uid={this.props.uid + '_permissions_steps'}
context="Hello World"
descriptionSource="props"
description={{
ui: {
showFooter: false,
showHeader: false
},
permissions: {
canCreate: true,
canDelete: true,
canRead: true,
canUpdate: true
},
columns: {
id_permission: {
type: "lookup",
title: "Permission",
model: "CeremonyCrmApp/Modules/Core/Settings/Models/Permission",
},
}
}}
></TableRolePermissions>
</InputTable>
{this.state.isInlineEditing ? (
<a
role='button'
onClick={() => {
if (!R.PERMISSIONS) R.PERMISSIONS = [];
R.PERMISSIONS.push({
id_role: { _useMasterRecordId_: true },
});
this.setState({ record: R });
}}
>
+ Add Permission
</a>
) : null}
</div>
</div>
</div>
</>
);
}
}
25 changes: 25 additions & 0 deletions src/priv/Components/Modules/Core/Settings/TableRolePermissions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { Component } from 'react'
import Table, { TableProps, TableState } from 'adios/Table';

interface TableRolePermissionsProps extends TableProps {
}

interface TableRolePermissionsState extends TableState {
}

export default class TableRolePermissions extends Table<TableRolePermissionsProps, TableRolePermissionsState> {
static defaultProps = {
...Table.defaultProps,
itemsPerPage: 15,
formUseModalSimple: true,
model: 'CeremonyCrmApp/Modules/Core/Settings/Models/RolePermission',
}

props: TableRolePermissionsProps;
state: TableRolePermissionsState;

constructor(props: TableRolePermissionsProps) {
super(props);
this.state = this.getStateFromProps(props);
}
}
31 changes: 31 additions & 0 deletions src/priv/Components/Modules/Core/Settings/TableUserRoles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { Component } from 'react'
import Table, { TableProps, TableState } from 'adios/Table';
import FormUserRoles from './FormUserRoles';

interface TableUserRolesProps extends TableProps {
}

interface TableUserRolesState extends TableState {
}

export default class TableUserRoles extends Table<TableUserRolesProps, TableUserRolesState> {
static defaultProps = {
...Table.defaultProps,
itemsPerPage: 15,
formUseModalSimple: true,
model: 'CeremonyCrmApp/Modules/Core/Settings/Models/UserRole',
}

props: TableUserRolesProps;
state: TableUserRolesState;

constructor(props: TableUserRolesProps) {
super(props);
this.state = this.getStateFromProps(props);
}

renderForm(): JSX.Element {
let formDescription = this.getFormProps();
return <FormUserRoles {...formDescription}/>;
}
}
2 changes: 2 additions & 0 deletions src/priv/Components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import CoreCustomersTableActivities from "./Modules/Core/Customers/TableActiviti
import CoreCustomersTableAddresses from "./Modules/Core/Customers/TableAddresses"
import CoreCustomersTableContacts from "./Modules/Core/Customers/TableContacts"
import CoreSettingsTablePipelines from "./Modules/Core/Settings/TablePipelines"
import CoreSettingsTableUserRoles from "./Modules/Core/Settings/TableUserRoles"

//billing
import CoreBillingTableBillingAccountService from "./Modules/Core/Billing/TableBillingAccountServices"
Expand Down Expand Up @@ -91,6 +92,7 @@ app.registerReactComponent('CoreCustomersTableAddresses', CoreCustomersTableAddr
app.registerReactComponent('CoreCustomersTableContacts', CoreCustomersTableContacts);
app.registerReactComponent('CoreSandboxTableCompanies', CoreSandboxTableCompanies);
app.registerReactComponent('CoreSettingsTablePipelines', CoreSettingsTablePipelines);
app.registerReactComponent('CoreSettingsTableUserRoles', CoreSettingsTableUserRoles);
//billing
app.registerReactComponent('CoreBillingTableBillingAccountService', CoreBillingTableBillingAccountService);
//sles
Expand Down
16 changes: 14 additions & 2 deletions src/publ/Core/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace CeremonyCrmApp\Core;

use CeremonyCrmApp\Modules\Core\Settings\Models\ {
Profile, User, UserRole, UserHasRole
Permission, Profile, RolePermission, User, UserRole, UserHasRole
};

class Account {
Expand Down Expand Up @@ -107,11 +107,15 @@ public function createDatabase()
$mUser = new User($this->app);
$mUserRole = new UserRole($this->app);
$mUserHasRole = new UserHasRole($this->app);
$mPermission = new Permission($this->app);
$mRolePermission = new RolePermission($this->app);

$mProfile->dropTableIfExists()->install();
$mUser->dropTableIfExists()->install();
$mUserRole->dropTableIfExists()->install();
$mUserHasRole->dropTableIfExists()->install();
$mPermission->dropTableIfExists()->install();
$mRolePermission->dropTableIfExists()->install();

$idProfile = $mProfile->eloquent->create(['company' => $this->companyName])->id;

Expand Down Expand Up @@ -179,6 +183,14 @@ public function generateTestData()
});
}

public function createPermissions() {
$registeredModules = $this->app->getRegisteredModules();
array_walk($registeredModules, function($moduleClass) {
$module = new $moduleClass($this->app);
$module->createPermissions();
});
}

public function createDevelScripts()
{
@mkdir($this->accountRootFolder . '/' . $this->uid . '/devel');
Expand All @@ -192,7 +204,7 @@ public function createDevelScripts()
public function getDatabaseUser(): string {
$dbUser = \ADIOS\Core\Helper::str2url($this->companyName);
$dbUser = str_replace('-', '_', $dbUser);
$dbUser =
$dbUser =
'usr_' . $dbUser
. ($this->randomize ? '_' . substr(md5(date('YmdHis').rand(1, 10000)), 1, 5) : '')
;
Expand Down
3 changes: 3 additions & 0 deletions src/publ/Core/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ public function modifySidebar(\CeremonyCrmApp\Core\Sidebar $sidebar) {
public function generateTestData() {
// to be overriden
}
public function createPermissions() {
// to be overriden
}
}
22 changes: 22 additions & 0 deletions src/publ/Modules/Core/Billing/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace CeremonyCrmApp\Modules\Core\Billing;

use CeremonyCrmApp\Modules\Core\Settings\Models\Permission;

class Loader extends \CeremonyCrmApp\Core\Module
{

Expand Down Expand Up @@ -45,7 +47,27 @@ public function generateTestData()
'id_company' => 1,
"description" => "Test Billing Account"
])->id; */
}

public function createPermissions()
{
$mPermission = new Permission($this->app);
$permissions = [
"Modules/Core/Billing/Models/BillingAccount:Create",
"Modules/Core/Billing/Models/BillingAccount:Read",
"Modules/Core/Billing/Models/BillingAccount:Update",
"Modules/Core/Billing/Models/BillingAccount:Delete",
"Modules/Core/Billing/Models/BillingAccountService:Create",
"Modules/Core/Billing/Models/BillingAccountService:Read",
"Modules/Core/Billing/Models/BillingAccountService:Update",
"Modules/Core/Billing/Models/BillingAccountService:Delete",
"Modules/Core/Billing/Controllers/BillingAccount",
];

foreach ($permissions as $key => $permission_string) {
$mPermission->eloquent->create([
"permission_string" => $permission_string
]);
}
}
}
52 changes: 49 additions & 3 deletions src/publ/Modules/Core/Customers/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CeremonyCrmApp\Modules\Core\Customers;

use CeremonyCrmApp\Modules\Core\Settings\Models\Permission;
use CeremonyCrmApp\Modules\Core\Settings\Models\Tag;

class Loader extends \CeremonyCrmApp\Core\Module
Expand Down Expand Up @@ -71,9 +72,6 @@ public function install() {
$mCompanyTag = new Models\CompanyTag($this->app);
$mCompanyTag->install();

$mAtendance = new Models\Atendance($this->app);
$mAtendance->install();

// pridat zaznamy do Core/Settings/Models/UserPermission
// pridat zaznamy do Core/Settings/Models/UserRolePermission
// pridat zaznamy do Core/Settings/Models/Setting (default values)
Expand All @@ -94,4 +92,52 @@ public function generateTestData()
'name' => "Category 3",
]);
}

public function createPermissions()
{
$mPermission = new Permission($this->app);
$permissions = [
"Modules/Core/Customers/Models/Activity:Create",
"Modules/Core/Customers/Models/Activity:Read",
"Modules/Core/Customers/Models/Activity:Update",
"Modules/Core/Customers/Models/Activity:Delete",
"Modules/Core/Customers/Models/Address:Create",
"Modules/Core/Customers/Models/Address:Read",
"Modules/Core/Customers/Models/Address:Update",
"Modules/Core/Customers/Models/Address:Delete",
"Modules/Core/Customers/Models/Company:Create",
"Modules/Core/Customers/Models/Company:Read",
"Modules/Core/Customers/Models/Company:Update",
"Modules/Core/Customers/Models/Company:Delete",
"Modules/Core/Customers/Models/CompanyTag:Create",
"Modules/Core/Customers/Models/CompanyTag:Read",
"Modules/Core/Customers/Models/CompanyTag:Update",
"Modules/Core/Customers/Models/CompanyTag:Delete",
"Modules/Core/Customers/Models/Contact:Create",
"Modules/Core/Customers/Models/Contact:Read",
"Modules/Core/Customers/Models/Contact:Update",
"Modules/Core/Customers/Models/Contact:Delete",
"Modules/Core/Customers/Models/Person:Create",
"Modules/Core/Customers/Models/Person:Read",
"Modules/Core/Customers/Models/Person:Update",
"Modules/Core/Customers/Models/Person:Delete",
"Modules/Core/Customers/Models/PersonTag:Create",
"Modules/Core/Customers/Models/PersonTag:Read",
"Modules/Core/Customers/Models/PersonTag:Update",
"Modules/Core/Customers/Models/PersonTag:Delete",
"Modules/Core/Customers/Controllers/Activity",
"Modules/Core/Customers/Controllers/Address",
"Modules/Core/Customers/Controllers/Company",
"Modules/Core/Customers/Controllers/CompanyTag",
"Modules/Core/Customers/Controllers/Contact",
"Modules/Core/Customers/Controllers/Person",
"Modules/Core/Customers/Controllers/PersonTag",
];

foreach ($permissions as $key => $permission_string) {
$mPermission->eloquent->create([
"permission_string" => $permission_string
]);
}
}
}
Loading

0 comments on commit 3dab28a

Please sign in to comment.