Skip to content

Instantly share code, notes, and snippets.

@davidknipe
Created November 24, 2016 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidknipe/3450252ef26bf2bd5b31467b682358d1 to your computer and use it in GitHub Desktop.
Save davidknipe/3450252ef26bf2bd5b31467b682358d1 to your computer and use it in GitHub Desktop.
using EPiServer.Shell.ContentQuery;
using System.Collections.Generic;
using System.Web;
using EPiServer;
using EPiServer.Approvals;
using EPiServer.Core;
using EPiServer.ServiceLocation;
using EPiServer.Shell.Rest;
using EPiServer.Shell.Services.Rest;
namespace AlloyDemoKit.Business.ContentApprovalExtensions
{
[ServiceConfiguration(typeof(IContentQuery))]
public class ContentApprovalForMeQuery : ContentApprovalQueryBase, IContentQuery
{
public ContentApprovalForMeQuery(IContentRepository contentRepository,
IApprovalRepository approvalRepository)
: base(contentRepository, approvalRepository)
{
}
public QueryRange<IContent> ExecuteQuery(IQueryParameters parameters)
{
var query = new ApprovalsQuery
{
OnlyActiveSteps = true,
Username = HttpContext.Current.User.Identity.Name
};
return this.ExecuteQueryInternal(query);
}
public string DisplayName => "Awaiting my approval";
public string Name => "awaitingmapproval";
public IEnumerable<string> PlugInAreas => new[] { "editortasks" };
public int SortOrder => 1;
}
public class ContentApprovalQueryBase
{
private readonly IContentRepository _contentRepository;
private readonly IApprovalRepository _approvalRepository;
public ContentApprovalQueryBase(IContentRepository contentRepository, IApprovalRepository approvalRepository)
{
_contentRepository = contentRepository;
_approvalRepository = approvalRepository;
}
public QueryRange<IContent> ExecuteQueryInternal(ApprovalsQuery query)
{
var itemsToBeApproved = _approvalRepository.ListAsync(query);
var contentItemsToBeApproved = new List<IContent>();
var result = itemsToBeApproved.Result;
foreach (var approval in result)
{
contentItemsToBeApproved.Add(_contentRepository.Get<IContent>(approval.ContentLink));
}
var items = new QueryRange<IContent>(contentItemsToBeApproved, new ItemRange());
return items;
}
public bool CanHandleQuery(IQueryParameters parameters) => true;
public int Rank { get; set; }
public bool VersionSpecific { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment