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.)

June 2, 2003: It's been a while since I was here... So long, apparently, that the XMLAPI had matured a lot. So I simplified the code here by using xml_locf and stuff. Also changed role addressing to work with "id" instead of "name" so that that would work. TODO: we really kind of need to think about global role assignments.
 
WFTK_EXPORT int    wftk_role_list   (XML * session, XML * datasheet, XML * list)
{
   int count = 0;
   XML * mark;
   XML_ATTR * attr;

   if (!list) return 0;
   mark = xml_firstelem (datasheet);
   while (mark) {
      if (xml_is (mark, "role")) {
         xml_append (list, xml_copy (mark));
         count++;
      }
      mark = xml_nextelem (mark);
   }

   xml_setnum (list, "count", count);
   return count;
}

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

   if (!role) return "";
   mark = xml_locf (datasheet, ".role[%s]", role);
   if (mark) return (xml_attrval (mark, "user"));

   return "";
}

WFTK_EXPORT int    wftk_role_assign (XML * 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_locf (datasheet, ".role[%s]", role);
   if (mark) {
      xml_set (mark, "user", userid);
      return 1;
   }

   mark = xml_create ("role");
   xml_set (mark, "id", role);
   xml_set (mark, "user", userid);
   xml_append_pretty (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 copyright (c) 2000-2004, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.