B
B
BonBon Slick2018-03-11 19:15:48
Software design
BonBon Slick, 2018-03-11 19:15:48

What is the best way to implement enabling and disabling functionality?

I have features, 1,2,3,4... however they are still at the testing stage and I want to disable them for the time being in production.
After testing, debugging, etc. upload to production, however, if something goes wrong, be able to turn off this functionality and block access to it. Let's say to issue a page that this feature is temporarily disabled. Quickly fix everything, upload it to the stage, then after the tests in production, and change the checkbox to indicate that the feature is enabled. As with the light in the room.
Has anyone already done this? Any ideas how to do it better?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-03-11
@BonBonSlick

It all depends on the architecture of your application, the presence of a front-end framework and other conditions.
But at the heart of the solution, in a good way, should be a system of access rights or display conditions, configured through the admin panel.
In React , I would write a PermissionChecker component that would check the permission keys written to the html template in window.__data . twig example :

<script>
window.__data = {
  permissions: {{ permissions|json_encode|raw }}
};
</script>

Array of application routes:
export const routes = [
  {
    path: '/feature1',
    component: feature1,
    requiredPermissions: PERMISSIONS.FEATURE_1,
  },
  ...
]

Small widgets in code:
render() {
  return(
    <Wrapper>
      ...
      <PermissionChecker
        requiredPermissions={PERMISSIONS.FEATURE_2}
      >
        <Feature2 />
      </PermissionChecker>
    </Wrapper>
  );
}

In the PermissionChecker implementation , permissions are checked and either componentb or null is returned . The same is in the component that draws the routes.
With this solution, you don't have to compile a new bundle in a hurry in case of errors, and features can be enabled and disabled via the admin panel. Moreover, the experimental functionality, if desired, can be given only to a certain circle of users. Here you implement a system of rights on the server.

R
rPman, 2018-03-11
@rPman

Once upon a time, I implemented a module system in such a way that one module is one plug-in file (in my case, php), when connected, the file is registered where necessary, adding the necessary items to the menu and buttons.
Accordingly, simply disabling include completely turned off the functionality.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question