Skip to content

Instantly share code, notes, and snippets.

View tarun-nagpal-github's full-sized avatar
💭
Code is like humor. When you have to explain it, it’s bad.

Tarun Nagpal tarun-nagpal-github

💭
Code is like humor. When you have to explain it, it’s bad.
View GitHub Profile
@tarun-nagpal-github
tarun-nagpal-github / roles-list.json
Created November 18, 2019 11:08
RBAC - Roles List
{
"data": {
"roles": [
{
"roleId": 2,
"roleName": "Administrator",
"isActive": true,
"__typename": "RoleType"
},
{
@tarun-nagpal-github
tarun-nagpal-github / module-and-pages.json
Created November 18, 2019 11:07
RBAC - Module and Pages
{
"data": {
"modules": [
{
"idUserModule": 1,
"userModuleName": "Client Setup",
"modulePages": [
{
"idUserModulePage": 12,
"pageName": "Client Settings All Pages",
{
"data": {
"user": {
"firstName": "Bob",
"lastName": "Marley",
"email": "bob@yahoo.com",
"Pages": [
{
"path": "/dashboard",
"name": "Dashboard",
@tarun-nagpal-github
tarun-nagpal-github / modal-mobile-web.html
Created September 9, 2019 06:14
modal-mobile-web.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script>
Array
(
[order_id] => 16
[order_data] => Array
(
[total] =>
[status] => pending
[currency] => ₹
[user_id] => 16
[payment] => cod
@tarun-nagpal-github
tarun-nagpal-github / Conditional-render.js
Last active August 9, 2019 10:23
Conditional-render.js
render(){
return (
<div className="buttonContainer">
// Button will only be displayed If Allowed Condition is True
{this.isActionAllowed('delete-record') &&
<button
type="button"
className="btn btn-secondary mt-3 ml-2"
onClick={this.closeReceiver}
isActionAllowed = (actionName = "") => {
return (this.props.actions.indexOf(actionName) >= 0) ? true : false;
}
const _ProtectedRoute = props => {
const { component: Component, path, permittedPages, stateOfuser, ...rest } = props;
const checkAccess = checkPageAccess(path, permittedPages);
//prettier-ignore
return <Route
{...rest}
render={props =>
((checkAccess.isUserAuthorised == false || typeof checkAccess.isUserAuthorised == 'undefined') && stateOfuser.loginSuccess ) ?
(<Redirect to={{pathname: "/un-authorised"}}/>) :
(<Component {...props} actions={checkAccess.allowedActionsName} />)
@tarun-nagpal-github
tarun-nagpal-github / checkPageAccess.js
Created August 9, 2019 09:51
API - Check Page Access
const checkPageAccess = (path, permittedPages) => {
let isUserAuthorised = false;
let url = path.replace(/\//g, "");
let allowedActions = [];
let allowedActionsName = [];
// If permittedPages exists
if( Array.isArray(permittedPages) && permittedPages.length > 0) {
isUserAuthorised = permittedPages.find(page => page.modulePageUrl === url);
permittedPages.forEach(element => {
import React from "react";
import { Route } from "react-router-dom";
import { Redirect } from "react-router";
import { connect } from "react-redux";
const checkPageAccess = (path, permittedPages) => {
let isUserAuthorised = false;
let url = path.replace(/\//g, "");
let allowedActions = [];
let allowedActionsName = [];