It's all about the answers!

Ask a question

Permission Error is reported when trying to upload a work item attachment using Plain Java API


0
1
Krasimir Malchev (56531) | asked Feb 06 '17, 1:57 p.m.

Environment:

RTC 6.0.2 Plain Java API

I have a work item created in a test CCM.

The work item is related to a team area where I have super user rights.

When I try to upload an attachment in that work item using the RTC Eclipse client, the work item is successfully saved and the attachment can be downloaded later.

On the other hand, I have created a Java command line application which main purpose is to save attachments automatically.

The code of the test application is taken from https://rsjazz.wordpress.com/2012/08/01/uploading-attachments-to-work-items/

Result: When I run the application I receive the following error:

   The 'Save Attachment' operation cannot be completed. Permission is required to complete the operation.

I use  the same user name and password as well as the same work item and files.

Q: How can I save the attachments using the API without the need to grant privileges in the project area, but only in the team area as I managed to do it manually using the Eclipse client?

Thanks!

Accepted answer


permanent link
Krasimir Malchev (56531) | answered Feb 07 '17, 9:38 a.m.

Hello.

We've finally managed to run the example successfully.

Here is how an attachment is created in the example:

private static void attachFile1(
    WorkItemWorkingCopy workingCopy,
    String name, String contentType,
    String encoding,
    IProgressMonitor monitor)
    throws TeamRepositoryException,
        IOException {
      
     File attachmentFile = new File(name);
     FileInputStream fis = new FileInputStream(attachmentFile);

     IWorkItem workItem = workingCopy.getWorkItem();
     IWorkItemClient workItemClient =

                 (IWorkItemClient) ((ITeamRepository)workItem.getOrigin()).getClientLibrary(IWorkItemClient.class);
     try {
            IAttachment newAttachment =
                 workItemClient.createAttachment( workItem.getProjectArea(),
                                                                        attachmentFile.getName(),
                                                                        "",
                                                                       contentType,
                                                                       encoding,
                                                                       fis,
                                                                       monitor);

            newAttachment = (IAttachment) newAttachment.getWorkingCopy();
            newAttachment = workItemClient.saveAttachment(newAttachment, monitor);
            IItemReference ref = WorkItemLinkTypes.createAttachmentReference(newAttachment);
            workingCopy.getReferences().add(WorkItemEndPoints.ATTACHMENT, ref);
     } finally {
           if (fis != null) {
                fis.close();
           }
     }
  }

}

Instead, we created the attachment like this, and it worked without the need to grant privileges on PA level:

private static void attachFile( WorkItemWorkingCopy workingCopy, String fileName)

             throws TeamRepositoryException, IOException {

             File attachmentFile = new File(fileName);

             IReference ref = IReferenceFactory

                                        .INSTANCE

                                        .createReferenceFromURI(

                                                           attachmentFile.toURI(),

                                                           attachmentFile.getName());

             workingCopy.getReferences().add(WorkItemEndPoints.ATTACHMENT, ref);

}

Ralph Schoon selected this answer as the correct answer

Comments
Ralph Schoon commented Feb 07 '17, 9:44 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 Thanks. Interesting, I will review my code.

2 other answers



permanent link
Alexander Pawlik (6128) | answered Feb 06 '17, 6:01 p.m.

 Krasimir,


Please send me your code (you know my email address) - I will have a look at it. We already implemented such a piece of code for your team and this one is working fine!

Best regards

Alexander


Comments
Krasimir Malchev commented Feb 07 '17, 3:33 a.m. | edited Feb 07 '17, 3:33 a.m.

 Hello, Alexander.


    I have sent the code to you.
    One note: If I have a "Product Lead" role on project area level (QA CCM1 > Training), the application works.

Thanks for your support!

Greetings,
   Krasimir.


Satish Narayanachar commented Mar 19 '19, 3:52 p.m.
Hi Krasimir,

Can you please send the code to me as well?

we are also looking at this functionality.

my mail id is satishn1987@gmail.com

Thanks in advance,
Satish

Ralph Schoon commented Mar 20 '19, 3:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

permanent link
Ralph Schoon (63.1k33645) | answered Feb 07 '17, 2:07 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Feb 07 '17, 2:29 a.m.

 1. There are no super users in RTC. Repository roles control what you can see and to some extend what you can do. You can have the repository role JazzAdmin, which gives you a lot more to see. It also gives you the ability to make yourself administrator and member of a project area. 


2. It however does not completely override the permission system. It only gives you the ability to create roles, assign roles and set permissions for roles. To be able to do more you still need to have the permissions either by Everyone having it or by giving you a role that has the permission.

3.You can not break the laws on roles, permissions, etc. using the API. You have to grant the user a role (or the default role everyone) the permission to save an attachment and the other permissions needed to see and save the work item.


Comments
Krasimir Malchev commented Feb 07 '17, 3:30 a.m.

 Hello, Ralf.


  Thanks for your fast response!

  Just one clarification: I have a role in a team area, which privileges allow me to attach a file to a work item (related to that team area). That being said, I am able to attach a file using the RTC Eclipse client without having any roles on the project area level.

  I use that same user configuration to run my command line application which tries to attach a file programmatically. However the latter generates the mentioned error.

 I was wondering why I can attach a file to the work item using the Eclipse client, but  I am not able to do it with the written application?

 Should I assume that the RTC Eclipse client uses an internal feature (which overcomes the lack of privileges on project area level) which is not exposed in the Plain Java API?
Note: My application successfully attaches a file if I add a corresponding role on project area level.

Greetings,
Krasimir Malchev


Ralph Schoon commented Feb 07 '17, 3:55 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I basically don't know. You should not be able to do things you have no permission to. If you are administrator in a project area, you gain the ability to define roles and give roles permissions and save the process XML - overriding the permission to do so, if you don't have it, If you have a JazzAdmin repository role you see work items even if they are hidden and you can make yourself admin of a project area etc.



I am not aware that Eclipse UI can override permissions. But I only know the API I have used and I only have access to the source on a SDK level like anyone.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.