# Role Concept

## Restrict a Job Function

| If the user USER1 is logged into Agile e6, he or she is permitted to make entries in the document master and the document type masks as a result of his or her assigned job function. However, this privilege has only been granted for documents who are either project-independent (i.e. which are not assigned to a specific project) or who are allocated to the FastViper project because the job function of the user is restricted to this project. As a prerequisite for this example, you must have performed the steps described in the previous examples.
| In the Access rule field of the existing tasks EDB-DOC-UPD,EDB-DOC-3DM-UPD ... EDB-DOC-TXT-UPD enter CUS_TASK/DocumentUpdate.
| These tasks should already have been assigned to the appropriate document masks with the Tasks checked in Masks list!
| Prepare the LogiView Procedure DocumentUpdate in the logic model CUS_TASK.
| Variables of the procedure
    EP_ALL_OKAY     L

    EP_COUNT        I      Counter

    EP_COUNT_PRO    I      Counter for projects

    EP_DOC_CID      I      "T_DOC_DAT.C_ID", actual C_ID of current document

                           record

    EP_FOUND        I      Number of found records

    EP_INDEX        I

    EP_PRO_ID_ARR   S 100  "T_PRO_DAT.PROJ_ID" Array with project ID's

    EP_STRING       S      arbitrary string

    EP_TSK_PRO_ARR  S 100  Array with projects for all tasks
    LogiView Procedure CUS_TASK/DocumentUpdate

    10  C -- The default is to assume no privilege

    20    EP_ALL_OKAY = FALSE

    30  C -- Get the C_ID of the current document

    40    EP_DOC_CID = sel_value("T_DOC_DAT.C_ID",actual)

    50  C -- Get all projects which are related to the document

    60    select_agg("EDB-DOCUMENT EDB-PROJECT STR")

    70    var(EP_PRO_ID_ARR[1])

    80    where_ent("T_DOC_DAT.C_ID" = EP_DOC_CID)

    90    EP_FOUND = execute(0)

    100   if (EP_FOUND > 0)

    110 C    -- The document has been assigned to one ore more projects.

    120      EP_STRING = ""

    130      EP_COUNT = split(EP_ROL_PRO,EP_TSK_PRO_ARR[1])

    140      if (EP_COUNT > 0)

    150 C    -- OK, the task is restricted to specific projects

    160 C    -- Is the user permitted to update the document?

    170 C    -- Check if the found projects match

    180 C    -- the projects defined for a job position.

    190      while (EP_FOUND > 0)

    200         if (EP_FOUND == 1)

    210           EP_STRING = strcat(EP_STRING,EP_PRO_ID_ARR[EP_FOUND])

    220         else

    230           EP_STRING = strcat(EP_STRING,EP_PRO_ID_ARR[EP_FOUND],",")

    240         endif

    250         EP_INDEX = EP_COUNT

    260         while (EP_INDEX > 0)

    270            if (EP_TSK_PRO_ARR[EP_INDEX] == EP_PRO_ID_ARR[EP_FOUND])

    280              EP_ALL_OKAY = TRUE

    290            endif

    300            EP_INDEX = EP_INDEX-1

    310         done

    320         EP_FOUND = EP_FOUND-1

    330      done

    340      else

    350 C       -- The privileges of the user are not restricted to specific projects

    360         EP_ALL_OKAY = TRUE

    370      endif

    380    else

    390 C    -- The document is not assigned to a specific project

    400 C    -- so let's assume it is a general document.

    410      EP_ALL_OKAY = TRUE

    420    endif

    430    if (EP_ALL_OKAY == FALSE)

    440 C    -- Return with 'exit' to generate an error

    450      put(strprint("This document is assigned to project(s) %s",EP_STRING))

    460      put(strprint("You can only update documents from project(s)

             %s",EP_ROL_PRO))

    470      exit()

    480    endif