anchor.diff:  
       SID = create_space_for_user(?SPACE_NAME1, UserReqParams2),
   %%
  -%%     set_group_user_privileges(GID, UserId2, [group_view_data, group_change_data], UserReqParams1),
  -%%
  -
  -%%
  +%     set_group_user_privileges(GID, UserId2, [group_view_data, group_change_data], UserReqParams1),
  +%
   %%     get_group_user_privileges(GID, UserId2, UserReqParams1),
   %% %%
   %%     set_group_user_privileges(GID, UserId2, [group_change_data], UserReqParams1),
  
positive.code:     group_privileges_check(Privileges, Users, GID, _SID).
  
  group_privilege_check(group_view_data, Users, GID, _SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
      %% user who belongs to group should have group_view_data privilege by default
      ?assertMatch([GID, ?GROUP_NAME1], read_group(GID, UserReqParams2)),
      clean_group_privileges(GID, UserId2, UserReqParams1);
  group_privilege_check(group_change_data, Users, GID, _SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
      %% test if user2 lacks group_change_data privileges
  
negative.code: clean_group_privileges(GID, UserId, ReqParams) ->
      set_group_user_privileges(GID, UserId, [group_view_data], ReqParams).
  
  %% Spaces functions
  
  %% version for user
  create_space(Name, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Body = jiffy:encode({[
          {name, Name}
      ]}),
      Response = do_request(RestAddress ++ "/spaces", Headers, post, Body, Options),
      get_header_val("spaces", Response).
  
  %% version with token is for provider
  create_space(Token, Name, Size, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Body = jiffy:encode({[
          {name, Name},
          {token, Token},
          {size, Size}
      ]}),
      Response = do_request(RestAddress ++ "/spaces", Headers, post, Body, Options),
      get_header_val("spaces", Response).
  
  read_space(SID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(RestAddress ++ "/spaces/" ++ binary_to_list(SID) , Headers, get,[], Options),
      get_body_val([spaceId, name], Response).
  
  update_space(Name, SID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
       Body = jiffy:encode({[
          {name, Name}
      ]}),
      do_request(RestAddress ++ "/spaces/" ++ binary_to_list(SID) , Headers, patch, Body, Options).
  
  delete_space(SID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      do_request(RestAddress ++ "/spaces/" ++ binary_to_list(SID) , Headers, delete, [], Options).
  
  get_space_users(SID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/users" , Headers, get, [], Options
          ),
      [Users] = get_body_val([users], Response),
      Users.
  
  get_space_user(SID, UID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/users/" ++ binary_to_list(UID),
              Headers, get, [], Options
          ),
      get_body_val([userId, name], Response).
  
  delete_space_user(SID, UID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      do_request(
          RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/users/" ++ binary_to_list(UID),
          Headers, delete, [], Options
      ).
  
  get_space_privileges(UserType, SID, ID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/" ++ atom_to_list(UserType) ++ "/"
                  ++ binary_to_list(ID) ++ "/privileges",
              Headers, get, [], Options
          ),
      [Priveleges] = get_body_val([priveleges], Response),
      Priveleges.
  
  set_space_privileges(UserType, SID, ID, Privileges, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Body = jiffy:encode({[
          {privileges, Privileges}
      ]}),
      do_request(
          RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/" ++ atom_to_list(UserType) ++ "/" ++
              binary_to_list(ID) ++ "/privileges",
          Headers, put, Body, Options
      ).
  
  get_space_groups(SID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/groups" , Headers, get, [], Options
          ),
      [Groups] = get_body_val([groups], Response),
      Groups.
  
  get_space_group(SID, GID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/groups/" ++ binary_to_list(GID),
              Headers, get, [], Options
          ),
      get_body_val([groupId, name],Response).
  
  delete_space_group(SID, GID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/groups/" ++ binary_to_list(GID),
              Headers, delete, [], Options
          ),
      Response.
  
  get_space_providers(SID, ReqParams) ->
  {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/providers",
              Headers, get, [], Options
          ),
      [Providers] = get_body_val([providers], Response),
      Providers.
  
  get_space_provider(SID, PID, ReqParams) ->
  {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/providers/" ++ binary_to_list(PID),
              Headers, get, [], Options
          ),
      get_body_val([clientName, providerId, urls, redirectionPoint], Response).
  
  delete_space_provider(SID, PID, ReqParams) ->
  {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++ "/providers/" ++ binary_to_list(PID),
              Headers, delete, [], Options
          ),
      Response.
  
  get_space_creation_token_for_user(ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response = do_request(RestAddress ++ "/user/spaces/token", Headers, get, [], Options),
      [Token] = get_body_val([token], Response),
      Token.
  
  get_space_creation_token_for_group(GID, ReqParams)->
      {RestAddress, Headers, Options} = ReqParams,
      Response = do_request(
          RestAddress ++ "/groups/"++ binary_to_list(GID) ++ "/spaces/token", Headers, get, [], Options
      ),
      [Token] = get_body_val([token], Response),
      Token.
  
  get_space_invitation_token(UserType, ID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response =
          do_request(
              RestAddress ++ "/spaces/" ++ binary_to_list(ID)++ "/" ++ atom_to_list(UserType)++"/token",
              Headers, get, [], Options
          ),
      [Token] = get_body_val([token], Response),
      Token.
  
  get_space_support_token(SID, ReqParams) ->
      {RestAddress, Headers, Options} = ReqParams,
      Response = do_request(
          RestAddress ++ "/spaces/" ++ binary_to_list(SID) ++"/providers/token",
          Headers, get, [], Options
      ),
      [Token] = get_body_val([token], Response),
      Token.
  
  space_privileges_check([], _, _, _) -> ok;
  space_privileges_check([FirstPrivilege | Privileges], Users, GID, _SID) ->
      ?PRINT("PRIVILEGE"),
      ?PRINT(FirstPrivilege),
      space_privilege_check(FirstPrivilege, Users, GID, _SID),
      space_privileges_check(Privileges, Users, GID, _SID).
  
  space_privilege_check(space_view_data, Users, _GID, SID) ->
      [{_UserId1, _UserReqParams1}, {_UserId2, UserReqParams2} | _] = Users,
      %% user who belongs to group should have space_view_data privilege by default
      ?assertMatch([SID, ?SPACE_NAME1], read_space(SID, UserReqParams2));
  space_privilege_check(space_change_data, Users, _GID, SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
      %% test if user2 lacks space_change_data privileges
      ?assertMatch(bad, check_status(update_space(SID, ?SPACE_NAME2, UserReqParams2))),
      set_space_privileges(users, SID, UserId2, [space_change_data], UserReqParams1),
      ?assertMatch(ok, check_status(update_space(SID, ?SPACE_NAME2, UserReqParams2))),
      clean_space_privileges(SID, UserId2, UserReqParams1);
  space_privilege_check(space_invite_user, Users, _GID, SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
      %% test if user2 lacks space_invite_user privileges
      ?assertMatch(bad, check_status(get_space_invitation_token(users, SID, UserReqParams2))),
      set_space_privileges(users, SID, UserId2, [space_invite_user], UserReqParams1),
      ?assertNotMatch(bad, check_status(get_space_invitation_token(users, SID, UserReqParams2))),
      clean_space_privileges(SID, UserId2, UserReqParams1);
  space_privilege_check(space_invite_group, Users, _GID, SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
      %% test if user2 lacks space_invite_user privileges
      ?assertMatch(bad, check_status(get_space_invitation_token(group, SID, UserReqParams2))),
      set_space_privileges(users, SID, UserId2, [space_invite_group], UserReqParams1),
      ?assertNotMatch(bad, check_status(get_space_invitation_token(group, SID, UserReqParams2))),
      clean_space_privileges(SID, UserId2, UserReqParams1);
  space_privilege_check(space_set_privileges, Users, _GID, SID) ->
      [{UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
       %% test if user2 lacks space_set_privileges privileges
      ?assertMatch(bad,
          check_status(set_space_privileges(users, SID, UserId1, ?SPACE_PRIVILEGES, UserReqParams2))
      ),
      set_space_privileges(users, SID, UserId2, [space_set_privileges], UserReqParams1),
      ?assertMatch(ok,
          check_status(set_space_privileges(users, SID, UserId1, ?SPACE_PRIVILEGES, UserReqParams2))
      ),
      clean_space_privileges(SID, UserId2, UserReqParams1);
  space_privilege_check(space_remove_user, Users, _GID, SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2}, {UserId3, UserReqParams3} | _] = Users,
      InvitationToken = get_space_invitation_token(users, SID, UserReqParams3),
      join_user_to_space(InvitationToken, UserReqParams3),
       %% test if user2 lacks space_remove_user privileges
      ?assertMatch(bad, check_status(delete_space_user(SID, UserId3, UserReqParams2))),
      set_space_privileges(users, SID, UserId2, [space_remove_user], UserReqParams1),
      ?assertMatch(ok,
          check_status(delete_space_user(SID, UserId3, UserReqParams2))
      ),
      clean_space_privileges(SID, UserId2, UserReqParams1);
  space_privilege_check(space_remove_group, Users, GID, SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
      InvitationToken = get_space_invitation_token(groups, SID, UserReqParams2),
      join_group_to_space(InvitationToken, GID, UserReqParams1),
       %% test if user2 lacks space_remove_group privileges
      ?assertMatch(bad,
          check_status(delete_space_group(SID, GID, UserReqParams2))
      ),
      set_space_privileges(users, SID, UserId2, [space_remove_group], UserReqParams1),
      ?assertMatch(ok,
          check_status(delete_space_group(SID, GID, UserReqParams2))
      ),
      clean_space_privileges(SID, UserId2, UserReqParams1);
  space_privilege_check(space_add_provider, Users, _GID, SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
       %% test if user2 lacks space_add_provider privileges
      ?assertMatch(bad, check_status(get_space_support_token(SID, UserReqParams2))),
      set_space_privileges(users, SID, UserId2, [space_add_provider], UserReqParams1),
      ?assertNotMatch(bad, check_status(get_space_support_token(SID, UserReqParams2))),
      clean_space_privileges(SID, UserId2, UserReqParams1);
  space_privilege_check(space_remove_provider, Users, _GID, SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
       %% test if user2 lacks space_remove_provider privileges
      [PID] = get_space_providers(SID, UserReqParams1),
      ?assertMatch(bad, check_status(delete_space_provider(SID, PID, UserReqParams2))),
      set_space_privileges(users, SID, UserId2, [space_remove_provider], UserReqParams1),
      ?assertNotMatch(bad, check_status(delete_space_provider(SID, PID, UserReqParams2))),
      clean_space_privileges(SID, UserId2, UserReqParams1);
  space_privilege_check(space_remove, Users, _GID, SID) ->
      [{_UserId1, UserReqParams1}, {UserId2, UserReqParams2} | _] = Users,
      %% test if user2 lacks space_remove privileges
      ?assertMatch(bad, check_status(delete_group(SID, UserReqParams2))),
      set_space_privileges(users, SID, UserId2, [space_remove], UserReqParams1),
      ?assertMatch(ok, check_status(delete_group(SID, UserReqParams2))).
  
  clean_space_privileges(SID, UserId, ReqParams) ->
      set_space_privileges(users, SID, UserId, [space_view_data], ReqParams).
  