Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions xwiki-platform-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@
</item>
</differences>
</revapi.differences>
<revapi.differences>
<justification>
Change in generated class of the REST model to add models for user endpoints.
</justification>
<criticality>allowed</criticality>
<differences>
<item>
<code>java.annotation.attributeValueChanged</code>
<old>class org.xwiki.rest.model.jaxb.LinkCollection</old>
<new>class org.xwiki.rest.model.jaxb.LinkCollection</new>
<annotationType>javax.xml.bind.annotation.XmlSeeAlso</annotationType>
<attribute>value</attribute>
<oldValue>{org.xwiki.rest.model.jaxb.HistorySummary.class, org.xwiki.rest.model.jaxb.Attribute.class, org.xwiki.rest.model.jaxb.Translation.class, org.xwiki.rest.model.jaxb.Client.class, org.xwiki.rest.model.jaxb.JobLog.class, org.xwiki.rest.model.jaxb.JobStatus.class, org.xwiki.rest.model.jaxb.Syntaxes.class, org.xwiki.rest.model.jaxb.SearchResults.class, org.xwiki.rest.model.jaxb.SearchResult.class, org.xwiki.rest.model.jaxb.Tags.class, org.xwiki.rest.model.jaxb.Tag.class, org.xwiki.rest.model.jaxb.Properties.class, org.xwiki.rest.model.jaxb.Translations.class, org.xwiki.rest.model.jaxb.ObjectSummary.class, org.xwiki.rest.model.jaxb.Objects.class, org.xwiki.rest.model.jaxb.Classes.class, org.xwiki.rest.model.jaxb.Class.class, org.xwiki.rest.model.jaxb.PropertyValues.class, org.xwiki.rest.model.jaxb.Property.class, org.xwiki.rest.model.jaxb.Attachment.class, org.xwiki.rest.model.jaxb.Comment.class, org.xwiki.rest.model.jaxb.Comments.class, org.xwiki.rest.model.jaxb.Attachments.class, org.xwiki.rest.model.jaxb.History.class, org.xwiki.rest.model.jaxb.PageSummary.class, org.xwiki.rest.model.jaxb.Space.class, org.xwiki.rest.model.jaxb.Wiki.class, org.xwiki.rest.model.jaxb.Pages.class, org.xwiki.rest.model.jaxb.Spaces.class, org.xwiki.rest.model.jaxb.Wikis.class, org.xwiki.rest.model.jaxb.Xwiki.class}</oldValue>
<newValue>{org.xwiki.rest.model.jaxb.HistorySummary.class, org.xwiki.rest.model.jaxb.Attribute.class, org.xwiki.rest.model.jaxb.Translation.class, org.xwiki.rest.model.jaxb.UserSummary.class, org.xwiki.rest.model.jaxb.Client.class, org.xwiki.rest.model.jaxb.JobLog.class, org.xwiki.rest.model.jaxb.JobStatus.class, org.xwiki.rest.model.jaxb.Syntaxes.class, org.xwiki.rest.model.jaxb.SearchResults.class, org.xwiki.rest.model.jaxb.SearchResult.class, org.xwiki.rest.model.jaxb.Tags.class, org.xwiki.rest.model.jaxb.Tag.class, org.xwiki.rest.model.jaxb.Properties.class, org.xwiki.rest.model.jaxb.Translations.class, org.xwiki.rest.model.jaxb.ObjectSummary.class, org.xwiki.rest.model.jaxb.Objects.class, org.xwiki.rest.model.jaxb.Classes.class, org.xwiki.rest.model.jaxb.Class.class, org.xwiki.rest.model.jaxb.PropertyValues.class, org.xwiki.rest.model.jaxb.Property.class, org.xwiki.rest.model.jaxb.Attachment.class, org.xwiki.rest.model.jaxb.Comment.class, org.xwiki.rest.model.jaxb.Comments.class, org.xwiki.rest.model.jaxb.Attachments.class, org.xwiki.rest.model.jaxb.History.class, org.xwiki.rest.model.jaxb.PageSummary.class, org.xwiki.rest.model.jaxb.Space.class, org.xwiki.rest.model.jaxb.Wiki.class, org.xwiki.rest.model.jaxb.Pages.class, org.xwiki.rest.model.jaxb.Spaces.class, org.xwiki.rest.model.jaxb.Wikis.class, org.xwiki.rest.model.jaxb.Xwiki.class}</newValue>
</item>
</differences>
</revapi.differences>


</analysisConfiguration>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rest.resources.user;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import org.xwiki.rest.XWikiRestException;
import org.xwiki.rest.model.jaxb.User;

/**
* @since 18.2.0RC1
* @version $Id$
*/
@Path("/wikis/{wikiName}/user")
public interface CurrentUserResource
{
@GET User getUser(
@PathParam("wikiName") String wikiName,
@QueryParam("preferences") boolean preferences
) throws XWikiRestException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rest.resources.user;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import org.xwiki.rest.XWikiRestException;
import org.xwiki.rest.model.jaxb.User;

/**
* @since 18.2.0RC1
* @version $Id$
*/
@Path("/wikis/{wikiName}/users/{userId}")
public interface UserResource
{
@GET User getUser(
@PathParam("wikiName") String wikiName,
@PathParam("userId") String userId,
@QueryParam("preferences") boolean preferences
) throws XWikiRestException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rest.resources.user;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import org.xwiki.rest.XWikiRestException;
import org.xwiki.rest.model.jaxb.Users;

/**
* @since 18.2.0RC1
* @version $Id$
*/
@Path("/wikis/{wikiName}/users")
public interface UsersResource
{
@GET Users getUsers(
@PathParam("wikiName") String wikiName,
@QueryParam("start") @DefaultValue("0") Integer start,
@QueryParam("number") Integer number
) throws XWikiRestException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ public final class Relations
*/
public static final String CLIENT = "http://www.xwiki.org/rel/client";

/**
* Relation for links pointing to the user.
*/
Copy link
Member

@tmortagne tmortagne Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @since (and @Unstable I guess).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

public static final String USER = "http://www.xwiki.org/rel/user";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you actually use it? Btw I'm surprised: there should be a dependency to xwiki-platform-user-rest somewhere if you want the model to reuse the UserSummary in some existing REST resources no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use it only in the users list endpoint, to point to the full user profile endpoint.
It could also be used in the existing REST endpoints, but that's a larger refactoring that I don't think I would like to include in this PR.


/**
* Avoid instantiation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,58 @@
</extension>
</simpleContent>
</complexType>

<complexType name="UserSummary">
<complexContent>
<extension base="xwiki:LinkCollection">
<sequence>
<element name="id" type="string"></element>
<element name="firstName" type="string"></element>
<element name="lastName" type="string"></element>
<element name="avatarUrl" type="string"></element>
<element name="global" type="boolean"></element>
<element name="xwikiRelativeUrl" type="string"></element>
<element name="xwikiAbsoluteUrl" type="string"></element>
</sequence>
</extension>
</complexContent>
</complexType>

<complexType name="UserPreferences">
<sequence>
<element name="displayHiddenDocuments" type="boolean"></element>
<element name="underlineLinks" type="string"></element>
<element name="timezone" type="string"></element>
<element name="editor" type="string"></element>
<element name="advanced" type="boolean"></element>
</sequence>
</complexType>

<complexType name="User">
<complexContent>
<extension base="xwiki:UserSummary">
<sequence>
<element name="displayName" type="string"></element>
<element name="company" type="string"></element>
<element name="about" type="string"></element>
<element name="email" type="string"></element>
<element name="phone" type="string"></element>
<element name="address" type="string"></element>
<element name="blog" type="string"></element>
<element name="blogFeed" type="string"></element>
<element name="preferences" type="xwiki:UserPreferences" minOccurs="0"></element>
</sequence>
</extension>
</complexContent>
</complexType>

<element name="users">
<complexType>
<sequence>
<element name="userSummary" type="xwiki:UserSummary" minOccurs="0" maxOccurs="unbounded"></element>
</sequence>
</complexType>
</element>

<element name="user" type="xwiki:User"></element>
</schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rest;

import java.net.URI;

import org.xwiki.component.annotation.Role;
import org.xwiki.rest.model.jaxb.User;
import org.xwiki.rest.model.jaxb.UserSummary;
import org.xwiki.user.UserReference;

import com.xpn.xwiki.XWikiException;

/**
* A component that converts a User Reference to REST API model elements.
*
* @since 18.2.0RC1
* @version $Id$
*/
@Role
public interface UserReferenceModelSerializer
{
/**
* Return a summary of the user's information to include in, e.g., user lists.
*
* @param baseUri the base URL of the current instance
* @param userId the id of the user (e.g., "wikiName:Space.Page" for a user stored as a document)
* @param userReference the user reference to serialize
* @return a user summary
* @throws XWikiException if there was a problem during serialization
*/
UserSummary toRestUserSummary(URI baseUri, String userId, UserReference userReference) throws XWikiException;

/**
* Return all the information available on the user.
*
* @param baseUri the base URL of the current instance
* @param userId the id of the user (e.g., "wikiName:Space.Page" for a user stored as a document)
* @param userReference the user reference to serialize
* @param preferences whether to include user preferences in the output
* @return a user
* @throws XWikiException if there was a problem during serialization
*/
User toRestUser(URI baseUri, String userId, UserReference userReference, boolean preferences) throws XWikiException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rest.internal.resources.user;

import java.net.URI;

import javax.ws.rs.ServerErrorException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import org.xwiki.component.annotation.Component;
import org.xwiki.localization.ContextualLocalizationManager;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.rest.UserReferenceModelSerializer;
import org.xwiki.rest.XWikiResource;
import org.xwiki.rest.XWikiRestException;
import org.xwiki.rest.model.jaxb.User;
import org.xwiki.rest.resources.user.CurrentUserResource;
import org.xwiki.user.UserReference;
import org.xwiki.user.UserReferenceResolver;
import org.xwiki.user.UserReferenceSerializer;

import com.xpn.xwiki.XWikiException;

import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Provider;

/**
* @since 18.2.0RC1
* @version $Id$
*/
@Component
@Named("org.xwiki.rest.internal.resources.user.CurrentUserResourceImpl")
public class CurrentUserResourceImpl extends XWikiResource implements CurrentUserResource
{
@Inject
@Named("document")
private UserReferenceResolver<DocumentReference> userReferenceResolver;

@Inject
private UserReferenceSerializer<String> stringUserReferenceSerializer;

@Inject
private Provider<UserReferenceModelSerializer> userReferenceModelSerializerProvider;

@Inject
private ContextualLocalizationManager contextualLocalizationManager;

@Override
public User getUser(String wikiName, boolean preferences) throws XWikiRestException
{
URI baseUri = this.uriInfo.getBaseUri();

// Fail if we don't have a serializer for the current user store.
UserReferenceModelSerializer userReferenceModelSerializer = this.userReferenceModelSerializerProvider.get();
if (userReferenceModelSerializer == null) {
throw new ServerErrorException(Response.status(Response.Status.NOT_IMPLEMENTED).entity(
this.contextualLocalizationManager.getTranslationPlain(
"rest.exception.userResource.unsupportedStore")).build());
}

DocumentReference userDocumentReference = this.xcontextProvider.get().getUserReference();
if (userDocumentReference == null) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}

try {
UserReference userReference = this.userReferenceResolver.resolve(userDocumentReference);

return userReferenceModelSerializer.toRestUser(baseUri,
this.stringUserReferenceSerializer.serialize(userReference), userReference, preferences);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
}
Loading