Skip to content

Implement candidate maintenance (fixes #72) #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 29 additions & 8 deletions Distribution/Server/Features/Html.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ initHtmlFeature ServerEnv{serverTemplatesDir, serverTemplatesMode,
-- Page templates
templates <- loadTemplates serverTemplatesMode
[serverTemplatesDir, serverTemplatesDir </> "Html"]
[ "maintain.html" ]
[ "maintain.html", "maintain-candidate.html" ]

-- do rec, tie the knot
rec let (feature, packageIndex, packagesPage) =
Expand Down Expand Up @@ -218,7 +218,7 @@ htmlFeature user
htmlUsers = mkHtmlUsers user usersdetails
htmlUploads = mkHtmlUploads utilities upload
htmlDownloads = mkHtmlDownloads utilities download
htmlCandidates = mkHtmlCandidates utilities core versions upload docsCandidates candidates
htmlCandidates = mkHtmlCandidates utilities core versions upload docsCandidates candidates templates
htmlPreferred = mkHtmlPreferred utilities core versions
htmlTags = mkHtmlTags utilities core list tags
htmlSearch = mkHtmlSearch utilities list names
Expand Down Expand Up @@ -493,7 +493,7 @@ mkHtmlCore HtmlUtilities{..}
Nothing -> noHtml
-- and put it all together
return $ toResponse $ Resource.XHtml $
Pages.packagePage render [tagLinks] [deprHtml] (beforeHtml ++ middleHtml ++ afterHtml) [] docURL
Pages.packagePage render [tagLinks] [deprHtml] (beforeHtml ++ middleHtml ++ afterHtml) [] docURL False
where
showDist (dname, info) = toHtml (display dname ++ ":") +++
anchor ! [href $ distroUrl info] << toHtml (display $ distroVersion info)
Expand Down Expand Up @@ -729,6 +729,7 @@ mkHtmlCandidates :: HtmlUtilities
-> UploadFeature
-> DocumentationFeature
-> PackageCandidatesFeature
-> Templates
-> HtmlCandidates
mkHtmlCandidates HtmlUtilities{..}
CoreFeature{ coreResource = CoreResource{packageInPath}
Expand All @@ -737,7 +738,8 @@ mkHtmlCandidates HtmlUtilities{..}
VersionsFeature{ queryGetPreferredInfo }
UploadFeature{ guardAuthorisedAsMaintainer }
DocumentationFeature{documentationResource, queryHasDocumentation}
PackageCandidatesFeature{..} = HtmlCandidates{..}
PackageCandidatesFeature{..}
templates = HtmlCandidates{..}
where
candidates = candidatesResource
candidatesCore = candidatesCoreResource
Expand Down Expand Up @@ -795,6 +797,13 @@ mkHtmlCandidates HtmlUtilities{..}
, resourceGet = [ ("html", servePublishForm) ]
, resourcePost = [ ("html", servePostPublish) ]
}
, (extendResource $ deletePage candidates) {
resourceDesc = [ (GET, "Show candidate deletion form")
, (POST, "Delete a package candidate")
]
, resourceGet = [ ("html", serveDeleteForm) ]
, resourcePost = [ ("html", doDeleteCandidate) ]
}
]

serveCandidateUploadForm :: DynamicPath -> ServerPartE Response
Expand All @@ -821,11 +830,13 @@ mkHtmlCandidates HtmlUtilities{..}
serveCandidateMaintain dpath = do
candidate <- packageInPath dpath >>= lookupCandidateId
guardAuthorisedAsMaintainer (packageName candidate)
return $ toResponse $ Resource.XHtml $ hackagePage "Maintain candidate"
[toHtml "Here, you can delete a candidate, publish it, upload a new one, and edit the maintainer group."]
template <- getTemplate templates "maintain-candidate.html"
return $ toResponse $ template
[ "pkgname" $= display (packageName candidate)
, "pkgversion" $= display (packageVersion candidate)
]
{-some useful URIs here: candidateUri check "" pkgid, packageCandidatesUri check "" pkgid, publishUri check "" pkgid-}


serveCandidatePage :: Resource -> DynamicPath -> ServerPartE Response
serveCandidatePage maintain dpath = do
cand <- packageInPath dpath >>= lookupCandidateId
Expand All @@ -848,7 +859,7 @@ mkHtmlCandidates HtmlUtilities{..}
[] -> []
warn -> [thediv ! [theclass "notification"] << [toHtml "Warnings:", unordList warn]]
return $ toResponse $ Resource.XHtml $
Pages.packagePage render [maintainHtml] warningBox sectionHtml [] docURL
Pages.packagePage render [maintainHtml] warningBox sectionHtml [] docURL True

servePublishForm :: DynamicPath -> ServerPartE Response
servePublishForm dpath = do
Expand Down Expand Up @@ -914,6 +925,16 @@ mkHtmlCandidates HtmlUtilities{..}
[] -> []
warns -> [paragraph << "There were some warnings:", unordList warns]

serveDeleteForm :: DynamicPath -> ServerPartE Response
serveDeleteForm dpath = do
candidate <- packageInPath dpath >>= lookupCandidateId
guardAuthorisedAsMaintainer (packageName candidate)
let pkgid = packageId candidate
return $ toResponse $ Resource.XHtml $ hackagePage "Deleting candidates"
[form ! [theclass "box", XHtml.method "post", action $ deleteUri candidatesResource "" pkgid]
<< input ! [thetype "submit", value "Delete package candidate"]]


{-------------------------------------------------------------------------------
Preferred versions
-------------------------------------------------------------------------------}
Expand Down
5 changes: 5 additions & 0 deletions Distribution/Server/Features/PackageCandidates.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ instance IsHackageFeature PackageCandidatesFeature where
data PackageCandidatesResource = PackageCandidatesResource {
packageCandidatesPage :: Resource,
publishPage :: Resource,
deletePage :: Resource,
packageCandidatesUri :: String -> PackageName -> String,
publishUri :: String -> PackageId -> String,
deleteUri :: String -> PackageId -> String,

-- TODO: Why don't the following entries have a corresponding entry
-- in CoreResource?
Expand Down Expand Up @@ -207,6 +209,7 @@ candidatesFeature ServerEnv{serverBlobStore = store}
candidatesResource = fix $ \r -> PackageCandidatesResource {
packageCandidatesPage = resourceAt "/package/:package/candidates/.:format"
, publishPage = resourceAt "/package/:package/candidate/publish.:format"
, deletePage = resourceAt "/package/:package/candidate/delete.:format"
, candidateContents = (resourceAt "/package/:package/candidate/src/..") {
resourceGet = [("", serveContents)]
}
Expand All @@ -217,6 +220,8 @@ candidatesFeature ServerEnv{serverBlobStore = store}
renderResource (packageCandidatesPage r) [display pkgname, format]
, publishUri = \format pkgid ->
renderResource (publishPage r) [display pkgid, format]
, deleteUri = \format pkgid ->
renderResource (deletePage r) [display pkgid, format]
, candidateChangeLogUri = \pkgid ->
renderResource (candidateChangeLog candidatesResource) [display pkgid, display (packageName pkgid)]
}
Expand Down
13 changes: 7 additions & 6 deletions Distribution/Server/Pages/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import System.FilePath.Posix ((</>), (<.>))
import System.Locale (defaultTimeLocale)
import Data.Time.Format (formatTime)

packagePage :: PackageRender -> [Html] -> [Html] -> [(String, Html)] -> [(String, Html)] -> Maybe URL -> Html
packagePage render headLinks top sections bottom docURL =
packagePage :: PackageRender -> [Html] -> [Html] -> [(String, Html)] -> [(String, Html)] -> Maybe URL -> Bool -> Html
packagePage render headLinks top sections bottom docURL isCandidate =
hackagePageWith [] docTitle docSubtitle docBody [docFooter]
where
pkgid = rendPkgId render
Expand All @@ -52,7 +52,7 @@ packagePage render headLinks top sections bottom docURL =
pkgBody render sections,
moduleSection render docURL,
downloadSection render,
maintainerSection pkgid,
maintainerSection pkgid isCandidate,
map pair bottom
]
bodyTitle = "The " ++ display (pkgName pkgid) ++ " package"
Expand Down Expand Up @@ -125,15 +125,16 @@ downloadSection PackageRender{..} =
srcURL = rendPkgUri </> "src/"
tarGzFileName = display rendPkgId ++ ".tar.gz"

maintainerSection :: PackageId -> [Html]
maintainerSection pkgid =
maintainerSection :: PackageId -> Bool -> [Html]
maintainerSection pkgid isCandidate =
[ h4 << "Maintainers' corner"
, paragraph << "For package maintainers and hackage trustees"
, ulist << li << anchor ! [href maintainURL]
<< "edit package information"
]
where
maintainURL = display (packageName pkgid) </> "maintain"
maintainURL | isCandidate = "candidate/maintain"
| otherwise = display (packageName pkgid) </> "maintain"

moduleSection :: PackageRender -> Maybe URL -> [Html]
moduleSection render docURL = maybeToList $ fmap msect (rendModules render)
Expand Down
39 changes: 39 additions & 0 deletions datafiles/templates/Html/maintain-candidate.html.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
$hackageCssTheme()$
<title>Hackage: Maintainers' page for $pkgname$-$pkgversion$ candidate</title>
</head>

<body>
$hackagePageHeader()$

<div id="content">
<h2>Maintainers' page for $pkgname$-$pkgversion$ candidate</h2>

<p>Here, you can delete a candidate, publish it, upload a new one, and
edit the maintainer group.

<dl>
<dt><a href="delete">Delete candidate</a></dt>
<dd>Discard this candidate (does not affect published packages).
</dd>

<dt><a href="publish">Publish candidate</a></dt>
<dd>Publish this candidate to make it visible in the main package database.
</dd>

<dt><a href="upload">Upload a new candidate</a></dt>
<dd>If you upload a new candidate with the same version as an
existing candidate, the older will be overwritten.
</dd>

<dt><a href="/package/$pkgname$/maintainers">Maintainer group</a></dt>
<dd>Only these users are allowed to upload new versions of the package.
Existing members can add other users into the maintainer group.
</dd>

</dl>

</div>
</body></html>