Example #1
0
        //Change the policy of the group
        public PermissionErrorCode ChangeGroupPolicy(string userRequestingChange, string groupname, GroupPolicyLevel newlevel)
        {
            //it must exist
            if (!GroupExists(groupname))
            {
                return(PermissionErrorCode.DoesNotExist);
            }
            //caller must be the owner
            if (!GetUserGroup(groupname).Owner.Equals(userRequestingChange, StringComparison.CurrentCultureIgnoreCase))
            {
                return(PermissionErrorCode.NotAuthorized);
            }

            var mConnection = GetConnection();

            using (var command = mConnection.CreateCommand())
            {
                command.CommandText = "{CALL SetGroupPolicy(?,?)}";
                command.Parameters.AddWithValue("ingroupname", groupname);
                command.Parameters.AddWithValue("plevel", newlevel);
                command.ExecuteScalar();
            }
            return(PermissionErrorCode.Ok);
        }
Example #2
0
 //Create a group
 public PermissionErrorCode CreateGroup(string Name, string owner, string Description, GroupPolicyLevel level)
 {
     try
     {
         var mConnection = GetConnection();
         using (var command = mConnection.CreateCommand())
         {
             command.CommandText = "{CALL CreateUserGroup(?,?,?,?)}";
             command.Parameters.AddWithValue("ingroupname", Name);
             command.Parameters.AddWithValue("inowner", owner);
             command.Parameters.AddWithValue("indescription", Description);
             command.Parameters.AddWithValue("inlevel", level);
             command.ExecuteScalar();
         }
         AddUserToGroup(owner, Name, owner);
     }
     catch (System.Data.Odbc.OdbcException ex)
     {
         if (ex.Message.Contains("Duplicate entry"))
         {
             return(PermissionErrorCode.AlreadyExists);
         }
         throw;
     }
     return(PermissionErrorCode.Ok);
 }