0 votes

Hi guys i ve made a really small tool to quickly see what rights are allowed with a security value and which is the security value I need to add for a specific set of rights.

find the fiddleJs here : https://jsfiddle.net/LouisMoisyChapel/eg4rqyt8/

this is how it works :
enter image description here

you can obviously set the wanted checkboxes to see the value
Or you can set a value and see the checkboxes result.

this is the full code (add it in a dialog ".htm" page and run it from efficy with a url like :
https://yourcrmserver/11.0/crm/dialog?page=dialog/securityConverter.htm
)

<%SetBookmark()%>
<%LoadMacros('MacroLibrary;MacroDialog')%>
<%Macro('Doctype')%>
<html lang="<%GetLanguage(lowercase=T)%>" dir="<%OnLanguage(ar='rtl', else='ltr')%>">
<head>
    <title> Manage Chart</title>
    <%Macro('MetaHead')%>
    <%UseStyleSheet(page='%%OnLanguage(ar="efficy-rtl", else="efficy")')%>
    <%UseScript('../lib/js/vendor/modernizr.js', fixedline=T, fixedpath=T)%>
    <style type="text/css">
        #rightselector {
            border: 1px #bbb solid;
            padding: 1rem;
        }

        #rightselector li{
            list-style: none;
        }

        #rightselector li span{
            margin-left: 1rem;
            vertical-align: top;
        }

        .NL_switch {
            position: relative;
            display: inline-block;
            width: 40px;
            height: 24px;
        }

        .NL_switch input {
            display: none;
        }

        .slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: #ccc;
        -webkit-transition: .4s;
        transition: .4s;
        }

        .slider:before {
        position: absolute;
        content: "";
        height: 18px;
        width: 18px;
        left: 2px;
        bottom: 3px;
        background-color: white;
        -webkit-transition: .4s;
        transition: .4s;
        }

        input:checked + .slider {
        background-color: #368a55;
        }

        input:focus + .slider {
        box-shadow: 0 0 1px #368a55;
        }

        input:checked + .slider:before {
        -webkit-transform: translateX(18px);
        -ms-transform: translateX(18px);
        transform: translateX(18px);
        }

        /* Rounded sliders */
        .slider.round {
        border-radius: 20px;
        }

        .slider.round:before {
        border-radius: 50%;
        }

    </style>
    <script>
        var securityValue = 0;
        var rights = [
            {value: 1, label: "Search"},
            {value: 2, label: "Read"},
            {value: 4, label: "Write"},
            {value: 8, label: "Delete"},
            {value: 16, label: "Show content"},
            {value: 32, label: "Add content"},
            {value: 64, label: "Update content"},
            {value: 128, label: "Delete content"},
            {value: 256, label: "Secure"},
            {value: 512, label: "Secure content"},
            {value: 2048, label: "No content"}                  
        ];

        /**
        * Load modules for widgets
        **/
        function Loaded(){

            requirejs([
                "jquery"
            ], function($){
                __debug = true;

                $.each(rights, function(_index, _item){
                    $("#rightselector").append("<li><label class='NL_switch'><input type='checkbox' id='right_" + _item.value + 
                        "' onclick='javascript:setSecurityValue();' class='item-checkbox'></input><div class='slider round'></div></label>" + 
                        "<span style='margin-bottom: 5px'>" + _item.label + "</span></li>")

                });

            });

            console.log("Page loaded"); 
        }

        function setSecurityValue(){
            securityValue = 0;
            $.each(rights, function(_index, _item){
                if ($("#right_" + _item.value).is(":checked")) securityValue += _item.value;
            });
            $("#securityvalue").val(securityValue);
        }

        function setRights(){
            securityValue = Number($("#securityvalue").val());
            $.each(rights, function(_index, _item){
                var temp = _item.value & securityValue;
                if (temp === _item.value) $("#right_" + _item.value).prop("checked", true);
                else $("#right_" + _item.value).prop("checked", false);
            });
        }

    </script>
</head>
<body onload="Loaded()" data-keep-size>
<div class="row dialog-wrapper" data-channel="dialog/main">
    <div class="small-12 columns button-group toolbar">
        <h3 class="section-title">
            <%GetLabel('Security converter')%>  
        </h3>   
    </div>

    <div class="row small-12 medium-6 large-4 columns left">    
        <ul id="rightselector">

        </ul>
        <label style="margin-left: 1.1rem;">Security value
            <input type=number width="100%" id="securityvalue" onchange="setRights()"/>
        </label>
    </div>
</div>

<!--</body>-->

<%Macro('DialogScriptsRequire')%>
<%UseScript('../../lib/js/jquery/jquery', fixedline=T)%>
<%UseScript('../../lib/js/fnd/foundation', fixedline=T)%>
</body>
</html> 

It should be enough to make it work (tell me if not)

It would be definitly cooler if Efficy could add it on Edn.
best regards

asked in Partners by (989 points)
edited by

1 Answer

0 votes

Regarding rights and permissions, it's better to avoid working with record permissions because it's static. Table rights can be tweaked far more easier. Don't forget they are more restrictive compared to group permissions.

I typically put Full Control (271) permission for all groups that have security on a record and reduce rights through Table Rights in Designer.
I avoid using user permissions, by not configuring record owner security in the default security tab.

Anyway, it looks cool!

Once I made a jsFiddle to do the opposite, knowing what powers of two are inside a number Old post

answered by (7.4k points)
unfortunatly i have no other choice that to use record security...
I will make a fiddle since that look definitly easier i ve made one^^ thanks for the idea

https://jsfiddle.net/LouisMoisyChapel/eg4rqyt8/
Welcome to Efficy Overflow, where you can ask questions and receive answers from other members of the community.
1,248 questions
1,518 answers
1,858 comments
328 users