Working with roles

Previous: Getting and setting process status ] [ Top:  ] [ Next: Working with users ]

Roles are pretty loose at this point. Basically, we want to be able to list the roles in a process, determine who's assigned to them at the moment (by default, once someone gets a task, that person gets further tasks assigned to that role in that process. The only way to get out of this is to de-assign the role or send a request to somebody else.)
 
WFTK_EXPORT int    wftk_role_list   (void * session, XML * datasheet, XML * list)
{
   int count = 0;
   XML * mark;
   XML * hit;
   XML_ATTR * attr;

   if (!list) return 0;
   mark = xml_firstelem (datasheet);
   while (mark) {
      if (xml_is (mark, "role")) {
         hit = xml_create ("role");
         attr = xml_attrfirst (mark);
         while (attr) {
            xml_set (hit, xml_attrname (attr), xml_attrvalue (attr));
            attr = xml_attrnext (attr);
         }
         xml_append (list, hit);
      }
      mark = xml_nextelem (mark);
   }

   return count;
}

WFTK_EXPORT const char * wftk_role_user (void * session, XML * datasheet, const char * role)
{
   XML * mark;

   if (!role) return "";
   mark = xml_firstelem (datasheet);
   while (mark) {
      if (xml_is (mark, "role") && !strcmp (xml_attrval (mark, "name"), role)) {
         return (xml_attrval (mark, "user"));
      }
      mark = xml_nextelem (mark);
   }

   return "";
}

WFTK_EXPORT int    wftk_role_assign (void * session, XML * datasheet, const char * role, const char * userid)
{
   XML * mark;

   if (!role || !userid) return 0;
   if (*userid) wftk_user_retrieve (session, datasheet, userid);

   /* TODO: reassign existing role-based tasks based on new role assignment. */

   mark = xml_firstelem (datasheet);
   while (mark) {
      if (xml_is (mark, "role") && !strcmp (xml_attrval (mark, "name"), role)) {
         xml_set (mark, "user", userid);
         return 1;
      }
      mark = xml_nextelem (mark);
   }

   mark = xml_create ("role");
   xml_set (mark, "name", role);
   xml_set (mark, "user", userid);
   xml_append (datasheet, mark);
   return 1;
}
Previous: Getting and setting process status ] [ Top:  ] [ Next: Working with users ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.